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 🙂

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
  • 5 replies
  • 532 views
  • 1 like
  • 2 in conversation