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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / 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

More SAS Interview Questions

How to convert .xls file into CSV format?

6 Answers   Quintiles,


describe how to adjust the performance of data integrator? : Sas-di

0 Answers  


Can you use a macro within another macro? If so how would SAS know where the current acro ended and the new one began?

1 Answers  


what are the differences between proc report and proc tabulate?

3 Answers  


Can you excute a macro within a macro? Describe.

3 Answers  






what other sas products have you used and consider yourself proficient in using? : Sas programming

0 Answers  


List down the reasons for choosing sas over other data analytics tools.

0 Answers  


how do i read multiple spaces in datasets? eg: vijaya raghava perumal.I tried with using & but it workss if its vijaya raghava but not for raghava perumal.how to do this?

8 Answers   Wipro, Xansa,


what are the considerations when picking a SAS/STAT procedure?

0 Answers   Accenture, Quintiles,


Explain input and put function?

0 Answers  


How do I CREATE an external dataset with sas code? I would like to create within a sascode a non-exsistent textfile on the host. So I am not forced to create the file befor filling it.

2 Answers  


Mention how to limit decimal places for the variable using proc means?

0 Answers  


Categories