BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11
/* data1, data2, data3, data4*/


%let readFrom = data1;

data thisdata;
set &readfrom;
run;

Hello team,

On the code on the top, The macro variable readFrom reads from data1, data2, data3 and data4. Each time we replace readfrom variable macro with data1, data2, data3 and data4

I want to save the result thisdata in a table , which is read from data1 and then append to it  thisdata when readfrom variable is replaced by data2.

We keep the result data1, then append to it data2, then data3 and data4.

Any help is greatly appreciated.

Regards,

blueblue

 

 

 

Blue Blue
3 REPLIES 3
SASKiwi
PROC Star

Don't think you need macro variables for that:

data thisdata;
set data1 - data4;
run;
s_lassen
Meteorite | Level 14

Unless you do something special with the data first, you can just read them in one fell swoop:

%let readfrom=data1 data2 data3 data_Test data_OK;
data thisdata;
set &readfrom;
run;

But if you need to do something special with each input data set first, you may want to do something like this:

%macro read_data(readfrom,out=final_output);
  %local i;
  %if %sysfunc(exist(&out)) %then %do;
    proc delete data=&out;run;
    %end;
   %do i=1 %to %sysfunc(countw(&readfrom));
      data temp_out;
          set %scan(&readfrom,&i);
      run;
      /* You will probably have more processing here, in this case */

/* if BASE dataset does not exist, the input is just copied, no problem */ proc append data=temp_out base=&out; run; %end; %mend; %read_data(&readfrom);
GN0001
Barite | Level 11

Hello team member,

I understood the first part only, that is enough for me for now. I will come back to this later. 
Blue & Black

Blue Blue

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