I have many datasets with the pattern:
T19AA032FELMOVETIMEACTIVITY
T19AA042FELMOVETIMEACTIVITY
T19AA052FELMOVETIMEACTIVITY
T19AA062FELMOVETIMEACTIVITY
T19AA072FELMOVETIMEACTIVITY
T19AA082FELMOVETIMEACTIVITY
T19AA092FELMOVETIMEACTIVITY
T19AA102FELMOVETIMEACTIVITY
T19AA112FELMOVETIMEACTIVITY
T19AA122FELMOVETIMEACTIVITY
T9AA031RTTMOVETIMEACTIVITY
T9AA041RTTMOVETIMEACTIVITY
T9AA051RTTMOVETIMEACTIVITY
T9AA061RTTMOVETIMEACTIVITY
T9AA071RTTMOVETIMEACTIVITY
T9AA081RTTMOVETIMEACTIVITY
T9AA091RTTMOVETIMEACTIVITY
T9AA101RTTMOVETIMEACTIVITY
T9AA111RTTMOVETIMEACTIVITY
T9AA121RTTMOVETIMEACTIVITY
I want to merge the datasets pairwise as following:
T9AA031RTTMOVETIMEACTIVITY with T19AA032FELMOVETIMEACTIVITY
T9AA041RTTMOVETIMEACTIVITY with T19AA042FELMOVETIMEACTIVITY
T9AA051RTTMOVETIMEACTIVITY with T19AA052FELMOVETIMEACTIVITY
You probably see the pattern here, but how do I do this with hundreds of files in a smooth way?
For example for these 3 :
T9AA031RTTMOVETIMEACTIVITY with T19AA032FELMOVETIMEACTIVITY
T9AA041RTTMOVETIMEACTIVITY with T19AA042FELMOVETIMEACTIVITY
T9AA051RTTMOVETIMEACTIVITY with T19AA052FELMOVETIMEACTIVITY
%Macro merges ;
%DO i = 3 %TO 5 ;
Data table_merges_&i ;
merge
T9AA0&i.1RTTMOVETIMEACTIVITY
T19AA0&i.2FELMOVETIMEACTIVITY
by yourvar ;
run ;
%END ;
%Mend merges
If they are named with just a number who changed, you can use a macro using a %DO loop :
I know that, but how?
I'm not used to working with dataset names, only with variables.
For example for these 3 :
T9AA031RTTMOVETIMEACTIVITY with T19AA032FELMOVETIMEACTIVITY
T9AA041RTTMOVETIMEACTIVITY with T19AA042FELMOVETIMEACTIVITY
T9AA051RTTMOVETIMEACTIVITY with T19AA052FELMOVETIMEACTIVITY
%Macro merges ;
%DO i = 3 %TO 5 ;
Data table_merges_&i ;
merge
T9AA0&i.1RTTMOVETIMEACTIVITY
T19AA0&i.2FELMOVETIMEACTIVITY
by yourvar ;
run ;
%END ;
%Mend merges
Okej, thank you, I can modify that a bit and make it work, I think.
This is working if your datasets have the same name but just a number who is changing 🙂
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.