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

Dear all,

 

I'm quite new to macro, and my question is:

I'm trying to merge 12 datasets together, named data_1 to data_12 with id and already sorted, and my code is

%macro mergedata;

%do i=1 %to 12;

data merged_data;

merge data_&i;

by id;

%end;

run;

%mend;

 

and it resulted in only the data from data_12. it seems that data_1 to data_11 were replaced and disappeared.

How should I rewrite that? Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
SAS_inquisitive
Lapis Lazuli | Level 10
%macro mergedata;
data merged_data;
  merge
%do i=1 %to 12;
 data_&i
%end;
  ;
  by id;
run;
%mend;

 

View solution in original post

4 REPLIES 4
SAS_inquisitive
Lapis Lazuli | Level 10
%macro mergedata;
data merged_data;
  merge
%do i=1 %to 12;
 data_&i
%end;
  ;
  by id;
run;
%mend;

 

Astounding
PROC Star

When writing a macro language program, you always, always, always have to know what the program would look like if you were not using macro language.  

 

@SAS_inquisitive has the right idea here.  It just needs a slight tweak, removing the extra semicolon here:

 

%do;

esilio
Calcite | Level 5
thanks a lot for advice. really helped a lot !
esilio
Calcite | Level 5
solved! thanks a lot

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