I have 637 folders, which contain 12,256 csv files. each folder may have different mumber of csv files.
each file is for one person. They all have the same header columns in all csv files.
I can important one file correctly. so based on that, I may be able to import and append all of them into one sungle file.
Can anyone kindly give me a template how to set up the loops to loop through all the folders and all the files in each folder?
Thank you very much
I read that post recently. Actually I used it successully when reading files in the same folder.
Now my task is more difficult, because I need to loop the folders as well.
I updated the answer to account for this. If you have issues, post your full code and error.
You'll need some modifications to the macro I linked to.
1. Get a list of files into a dataset, use the OS to list files. There's quite a few samples on here so a short search should pop up something.
2. Create a reference to a file - dummy file not used.
file my_file 'myfile.txt';
3. SET the data set from #1 into the data set
4. Modify the infile statement to use the variable from #1 that contains the file path using the filevar option.
infile my_file eov=eov filevar=myfile filename=filename truncover;
How about a combination of FILEVAR and wildcard? These folder names are UNIX. I forget your OS. You can use programming (not shown) to create your 600 or so folder paths.
data folders;
input folder $80.;
cards;
~/folder01
~/folder02
;;;;
run;
data _null_;
set folders;
length filename filevar $128;
filevar=catx('/',folder,'*.csv');
put filevar=;
infile dummy filevar=filevar filename=filename eov=eov end=eof;
do _n_ = 1 by 1 while(not eof);
input @;
if _n_ eq 1 or eof then do;
put 'NOTE: ' filename= eov=;
end;
input;
end;
run;
I found a good macro to loop all folders http://support.sas.com/kb/45/805.html
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: