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
What is a pdv and what are its functions?
what are the softwares and applications that are used most frequently used by sas bi applications developers? : Sas-bi
Compare sas with other data analytics tools.
describe about physical data integration? : Sas-di
What do the SAS log messages "numeric values have been converted to character" mean?
Mention how to limit decimal places for the variable using proc means?
explain the function of substr in sas? : Sas-administrator
Why and when do you use proc sql?
What is interleaving in SAS?
Is the physical structure of the data set in the same orientation as the report? Do you need to reshape the data sets? What method should you use to reshape the data–DATA steps,PROC TRANSPOSE,output data set from a procedure?
How to limit decimal places for the variable using proc means?
What is the purpose of _character_ and _numeric_?
How would you identify a macro variable?
What are the different versions of sas that you have used until now? : sas-grid-administration
What would be the result of the following SAS function (given that 31 Dec, 2000 is Sunday)?