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

/*step 1: create a macro for the destination folder */

%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;

/* step 2 , append all the files in one. */
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;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which command is used to save logs in the external file?

789


What is the length assigned to the target variable by the scan function?

889


Give some examples where proc report’s defaults are different than proc print’s defaults?

799


What is the different between functions and PROCs that calculate the same simple descriptive statistics?

1508


For what purposes have you used sas macros? : sas-macro

748


what type of graphs we will create(for 2+years candidates)?

2082


What are the features of SAS?

777


Name types of category in which SAS Informats are placed?

921


how the sas basic syntax style described? : Sas-administrator

790


In sas admin differentiate between roles and capabilities? : sas-grid-administration

754


What is the difference between %put and symbolgen? : sas-macro

908


what are some differences between proc summary and proc means? : Sas programming

740


what is data integration? : Sas-di

834


Explain the main difference between the sas procedures and functions? : Sas-administrator

754


What are the differences between sum function and using “+” operator?

786