Hi Everyone,
I follow this below code to import all CSV file from a folder.
https://github.com/statgeek/SAS-Tutorials/blob/master/Import_all_files_one_type
The first step is to create a list, then run a macro through the list to create test1, test2... file
For each file, say test2, i would like to add a variable name order, which will take value 2.
So when I comebine all data, I know the original data of a given row.
Any help is very much appreciate.
HC
You need to provide more context as all you linked to was a program that is pretty generic.
If you want to add a new variable to a dataset that you create using PROC IMPORT like that program does then you will need to use a new step. Something like
data test2 ;
order=2;
set test2 ;
run;
So if you have a macro variable named ORDER that was driving the process and used to generate the dataset names then perhaps that code in the middle of a macro might look like;
data test&order ;
order=ℴ
set test&order ;
run;
If you already have a series of dataset and you want to combine them and add a variable to indicate where a particular observation came from look at using the INDSNAME option on the SET statement. So this code will combine 200 datasets into one and make a new variable named MEMBERNAME that has the dataset name.
data all_tables ;
length dsname $200 membername $32 ;
set test1 - test200 indsname=dsname;
membername=scan(dsname,-1,'.');
run;
You need to provide more context as all you linked to was a program that is pretty generic.
If you want to add a new variable to a dataset that you create using PROC IMPORT like that program does then you will need to use a new step. Something like
data test2 ;
order=2;
set test2 ;
run;
So if you have a macro variable named ORDER that was driving the process and used to generate the dataset names then perhaps that code in the middle of a macro might look like;
data test&order ;
order=ℴ
set test&order ;
run;
If you already have a series of dataset and you want to combine them and add a variable to indicate where a particular observation came from look at using the INDSNAME option on the SET statement. So this code will combine 200 datasets into one and make a new variable named MEMBERNAME that has the dataset name.
data all_tables ;
length dsname $200 membername $32 ;
set test1 - test200 indsname=dsname;
membername=scan(dsname,-1,'.');
run;
Thank you so much as always, Tom.
HC
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.