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

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? 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Onizuka
Pyrite | Level 9

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

View solution in original post

5 REPLIES 5
Onizuka
Pyrite | Level 9

If they are named with just a number who changed, you can use a macro using a %DO loop :

 

 

 

TobbeNord
Obsidian | Level 7

I know that, but how? 

I'm not used to working with dataset names, only with variables. 

 

 

Onizuka
Pyrite | Level 9

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
TobbeNord
Obsidian | Level 7

Okej, thank you, I can modify that a bit and make it work, I think. 

Onizuka
Pyrite | Level 9

This is working if your datasets have the same name but just a number who is changing 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1322 views
  • 1 like
  • 2 in conversation