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

Hello,

 

Is there a way to merge files by using SET while adding new columns, like this:

 

%let x=%str(XXX._XX_);
%let z=JUN2017;


%macro merge(y);
data b&y;
set
%do i=1 %to &y;
%let i2=%sysfunc(putn(&i,Z2));
&x.&i2.&z

date = "&i2.&z";
%end;;

run;
%mend;

 

%merge(10);

 

I am not sure where to put the red part, basically, I want to add a new Date column every time it go thru each SET (the original files dont have Date column in it, just marked in the file name)

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can do that, but it may be easier to use the INDSNAME option instead. 

 

This isn't a MERGE, it's an APPEND, since all data sets seem to have a common prefix you may be able to avoid a macro entirely.

 

data want;

set xxx._xx: indsname = source;

date = source;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

You can do that, but it may be easier to use the INDSNAME option instead. 

 

This isn't a MERGE, it's an APPEND, since all data sets seem to have a common prefix you may be able to avoid a macro entirely.

 

data want;

set xxx._xx: indsname = source;

date = source;

run;
mkeintz
PROC Star

Probably all the incoming datasets have the same variables.  If so, I recommend adding the "open=defer" option to the SET statement:

 

  set xxx.xx_:   indsname=source open=defer;

 

Instead of generating one buffer per incoming data set, this option re-uses the same buffer for each dataset.  Saves memory, with no real performance cost.   And if the OP has not only ddJUN2017, but also the other months (ddJAN2017 ... ddDEC2017), a lot of memory gets saved.

 

The only problem would be the result would not be in chronological order (since all datasets named XXX.XX_ are read in alphabetical order).

 

 

 

 

 

--------------------------
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

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

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