i have multiple .csv files in a unix directory.
every file is having variable names as header.even for empty file also.

suppose take 3 files
a.csv
b.csv
c.csv

a.csv contains data as
name;age,salary;
raja;34;4000;
ravi;33;5000;
kumar;25;3000;

b.csv contains data as
name;age,salary;
ajay;40;4500;


and c.csv contains
name;age,salary; (only headers)

Now i want to import and append all these files in to a single dataset.

i tried infile statement with *.csv to import all at a time.

but i m not getting correct data.
please help me . its urgent.
thank you in advance

Answer Posted / vrana95

/*So for this, you have to create a macro to store the path of the folder where your files are located .*/

/*STEP 1:*/

%let dirname = C:UsersRANAJIDesktopSAS_Class_CodeMultiple_csv_files;
filename DIRLIST pipe "dir /B &dirname*.csv";

data dirlist ;
length fname $256;
infile dirlist length=reclen;
input fname $varying256. reclen ;
run;
proc print data = dirlist;
run;

/* so , once your all files are located there, you can proceed with step 2 */

/* Step2*/

data all_text (drop=fname);
length myfilename $100;
length name $25;
set dirlist;
filepath = "&dirname"||fname;
infile dummy filevar = filepath length=reclen end=done missover;
do while(not done);
myfilename = filepath;
input name $ x1 x2 x3;
output;
end;
run;
proc print data=all_text;
run;

you will have all the files appended in the new dataset.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between format and informat? : sas-grid-administration

576


how does sas handle missing values in: assignment statements, functions, a merge, an update, sort order, formats, procs? : Sas programming

596


how many display types available in sas bi dashboard? : Sas-bi

636


What is data _null_?

691


Which statement does not perform automatic conversions in comparisons?

1202






in the flow of data step processing, what is the first action in a typical data step? : Sas programming

648


Describe a time when you were really stuck on a problem and how you solved it?

2201


What was the last computer book you purchased? Why?

1910


Mention some common errors that are usually committed in sas programming.

588


Mention sas system options to debug sas macros.

659


how can you create zero observation dataset? : Sas programming

631


Explain the use of proc print and proc contents?

556


How do you connect the desktop application to metadata server? : sas-grid-administration

580


what is sas and what are the functions? : Sas-administrator

538


Name some categories in sas 9? : sas-grid-administration

555