BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
benjamin_2018
Fluorite | Level 6

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;
benjamin_2018
Fluorite | Level 6
Thank you Tom!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 7537 views
  • 3 likes
  • 2 in conversation