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

Hi folks,

 

Say I have data sets: Onedata1, Onedata2,  Twodata1, Twodata2, Threedata1, Threedata2, which have the same structure.

 

I can simply merge them like this:

 

Data combine;

set Onedata1 Onedata2  Twodata1 Twodata2 Threedata1 Threedata2;

run;

 

However, I'm wondering is there an alternative way to merge them, to make loops on one to three and 1 to 2, so that I don't need to list all of them after set statement. Thanks.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Okay @liyongkai800  you do makes sense. If the texts are in a library, you could query dictionary tables and load the values in a macro var and call in the set statement. If there is a pattern in the names. the filtering can be easy. But either way, it's gonna be a tedious and not so cool. 

 

Please do one thing, post a more "representative" sample of your names and somebody might have a better idea. Chill

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

I find loops creating texts boring

why not?

 

 

Data combine;

set Onedata:  Twodata:Threedata:;

run;

If you have just sets of 2

 

liyongkai800
Obsidian | Level 7
Thanks, that does save 1 to 3. However, the texts actually mean something in my original question, and it has more than three groups. Then I still need something like onedata:...... twentydata:;
novinosrin
Tourmaline | Level 20

Okay @liyongkai800  you do makes sense. If the texts are in a library, you could query dictionary tables and load the values in a macro var and call in the set statement. If there is a pattern in the names. the filtering can be easy. But either way, it's gonna be a tedious and not so cool. 

 

Please do one thing, post a more "representative" sample of your names and somebody might have a better idea. Chill

liyongkai800
Obsidian | Level 7
Yes, dictionary.tables can be used to create a list to store all data sets. I missed some features in my question.
ballardw
Super User

@liyongkai800 wrote:
Thanks, that does save 1 to 3. However, the texts actually mean something in my original question, and it has more than three groups. Then I still need something like onedata:...... twentydata:;

What texts? Your original question doesn't reference any "texts".

 

If you mean something related to the name of the contributing data set you can add that with the Indsname option:

Data combine;
   set Onedata:  Twodata:Threedata: indsname=ds;
   source = ds;
run;

DS would be a temporary variable that exists only for the duration of the data step. It holds the name of the data set the current record is from.

I assigned the value to another variable so you could see it after the step ends. You could parse your set name for any processing you might need that is different based on the name.

Or perhaps assign a custom format to the text to display considerably longer text then the variable would have.

PaigeMiller
Diamond | Level 26

Yes, you can do this with a macro or CALL EXECUTE.

 

But you need to be more specific about the problem. Are you talking about ALL of the data sets in a library, or some? If some, how would you identify the ones that are to be merged? Is all of this merging done one-to-one, or BY some variable?

--
Paige Miller

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
  • 6 replies
  • 676 views
  • 3 likes
  • 4 in conversation