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
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 25. 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.