Help using Base SAS procedures

Want to append 10 datasets into one dataset using Macro.

Reply
Occasional Contributor
Posts: 11

Want to append 10 datasets into one dataset using Macro.


I have 10datasets of monthly wise data, table names are like IND_UA_012018, IND_UA_022018, IND_UA_032018, IND_UA_042018,....IND_UA_102018.
I want macro code to append all the 10 datasets into one table using a macro

Respected Advisor
Posts: 3,040

Re: Want to append 10 datasets into one dataset using Macro.

UNTESTED CODE

 

%macro dothis;
    %do i=1 %to 10;
		%let monthyear=%sysfunc(mdy(&i,1,2018));
		%let filename=IND_UA_%sysfunc(putn(&monthyear,mmyyn6.));
		proc append base=all new=&filename;
                run;
	%end;
%mend;
%dothis
--
Paige Miller
SAS Super FREQ
Posts: 4,242

Re: Want to append 10 datasets into one dataset using Macro.

[ Edited ]

If these are the only data sets that start with the prefix IND_UA_ then there is no need to use a macro:

 

data All;
set IND_UA_: ;
run;

Trusted Advisor
Posts: 1,345

Re: Want to append 10 datasets into one dataset using Macro.

And if all those datasets have the same variables and variable attributes, you can add the "open=defer" option to the SET statement.  "open=defer" tells sas to re-use the same input buffer for each incoming data set.  Otherwise a memory buffer is generated for each incoming data set.  We often use this option when concatenating daily data sets over a quarter year.

 

 

data All;
set IND_UA_:   open=defer;
run;

Ask a Question
Discussion stats
  • 3 replies
  • 142 views
  • 2 likes
  • 4 in conversation