BookmarkSubscribeRSS Feed
Naveen45
Fluorite | Level 6


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

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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
Rick_SAS
SAS Super FREQ

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;

mkeintz
PROC Star

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;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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