Community,
I have several datasets with quarterly survey data, each with the same set of variables. I want to create one dataset from these multiple datasets without having to copy and paste the same steps with slightly different dataset names. I am a bit new to SAS so this is beyond my skill level. Can I use a do loop to read data from multiple datasets if I just use the index variable in the name of the dataset? Or is there a different and better way?
Here is the basic scenario. I have 4 datasets.
vacancy_data_1
vacancy_data_2
vacancy_data_3
vacancy_data_4
I want to create 1 dataset that combines these 4 separate dataset in order to output a graph of, for example, a change in a varaible over time, since these are quarterly datasets.
My best guess is:
data vacancy_data_combined;
do i=1 to 4;
set vacancy_data_i;
end;
run;
Thank you.
There is no need for any DO loop to concatenate datasets. Just list them all on the SET statement.
data vacancy_data_combined;
set vacancy_data_1 vacancy_data_2 vacancy_data_3 vacancy_data_4 ;
run;
If they really do have a simple range of numeric suffixes then you can use a member name list.
data vacancy_data_combined;
set vacancy_data_1 - vacancy_data_4 ;
run;
Or if all of them have the same prefix (and no other datasets use that prefix) you can use the colon wildcard to make the member name list.
data vacancy_data_combined;
set vacancy_data_: ;
run;
There is no need for any DO loop to concatenate datasets. Just list them all on the SET statement.
data vacancy_data_combined;
set vacancy_data_1 vacancy_data_2 vacancy_data_3 vacancy_data_4 ;
run;
If they really do have a simple range of numeric suffixes then you can use a member name list.
data vacancy_data_combined;
set vacancy_data_1 - vacancy_data_4 ;
run;
Or if all of them have the same prefix (and no other datasets use that prefix) you can use the colon wildcard to make the member name list.
data vacancy_data_combined;
set vacancy_data_: ;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.