02-24-2016 03:25 PM
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
02-24-2016 03:33 PM
02-24-2016 03:37 PM
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.
02-24-2016 04:19 PM
I updated the answer to account for this. If you have issues, post your full code and error.
02-24-2016 03:39 PM
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;
02-24-2016 04:32 PM - edited 02-24-2016 04:49 PM
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;