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
What is the difference between input and infile statement?
what can you learn from the sas log when debugging? : Sas programming
What is the use of stop statement?
Explain the special input delimiters used in sas programming.
explain the use of % includes a statement in sas? : Sas-administrator
what is sas application server, database server, sas olap server and sas metadata server? : Sas-di
What do you know about symput and symget?
What do you understand by the term Normal Distribution?
which date function advances a date, time or datetime value by a given interval? : Sas programming
what type of graphs we will create(for 2+years candidates)?
In SAS explain which statement does not perform automatic conversions in comparisons?
Can you execute macro within another macro? If so, how would sas know where the current macro ended and the new one began? : sas-macro
How to import multiple xls files into sas. Out of those files, how to get different values from a single variable and how to find number of rows per value type? We can do this using group by for one xls file with proc sql. Was wondering how I can achieve this for multiple files at the same time. Any ideas?
what are the new features included in the new version of sas i.e., Sas 9.1.3? : Sas programming
how do you debug and test your sas programs? : Sas programming