I have the following dataset and need to split it into separate files based on DATE and ID. I need to use a combination of the two variables as the file names, for example, "JAN2001_1.CSV". I do not know ex ante how many groups there are. Any help would be greatly appreciated!
DATE ID VAR1 VAR2 VAR3
JAN2001 1 ... ... ...
JAN2001 2 ... ... ...
JAN2002 1 ... ... ...
JAN2002 2 ... ... ...
Do you have your data in a SAS data set? If so, your data set name goes where I put "have".
The path you want your data to go to replaces "c:\folder\subfolder".
Put the names of the variables you want to output to the file on the put statement.
The program is basically complete for the splitting. Nothing more to do.
If you haven't read the data into SAS yet, that is the first step. If that is the case, you may want to sort by Date and ID after reading it and before the Data _null_ code..
Create a variable to hold the output file name, the FILEVAR options and Put:
data _null_;
set have;
length MyOut $ 200;
MyOut = cats("c:\folder\subfolder",date,"_",ID,".CSV");
file outfile Filevar=MyOut dlm=',';
put DATE ID VAR1 VAR2 VAR3;
run;
Sorry I really don't know how the rest of the program would look like. Can you provide more information? Thank you.
Do you have your data in a SAS data set? If so, your data set name goes where I put "have".
The path you want your data to go to replaces "c:\folder\subfolder".
Put the names of the variables you want to output to the file on the put statement.
The program is basically complete for the splitting. Nothing more to do.
If you haven't read the data into SAS yet, that is the first step. If that is the case, you may want to sort by Date and ID after reading it and before the Data _null_ code..
Thank you it worked!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.