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.
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
I find loops creating texts boring
why not?
Data combine;
set Onedata: Twodata:Threedata:;
run;
If you have just sets of 2
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 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.
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?
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.