Hello All, I am using SAS 9.4.
I have a 101 CSV files in the directory. I want to combine all csv files into one single CSV file /one dataset .
Everyday one csv file will add into the same directory and I need to combine all csv files into one single csv file again.
Can you please help me with the sas code
Do want a SAS data set or a CSV file?
A data step can read multiple CSV files into a single SAS data set IF the CSV files all have the same structure.
Do you have code to read a single CSV file? As a data step?
When you combine all the data do you need to add any information about which file it came from?
Here's a rough idea on how to read all files into a single SAS data set in one step:
If all of the CSV files have the same structure and are either all of the CSV files in that folder or all that follow a simple pattern then just use a single data step with a wildcard, * , in the filename.
So something like this:
data want;
length fname $256;
infile "\\my directory\*.csv" dsd truncover filename=fname;
input @;
if fname ne lag(fname) then delete;
length firstvar 8 secondvar $40 lastvar 8;
informat lastvar date.;
format lastvar date9.;
input firstvar -- lastvar;
run;
If the files are really large you might need to work harder by keeping track of which files you already read so you know which ones are new, but if the files are not that big then it is probably just easier to read the all each time.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.