BookmarkSubscribeRSS Feed
Planck
Obsidian | Level 7

Hi,

 

filename code temp;
data C;
  set A nobs=nobs ;
  file code ;
  do part=0 to int(nobs/1000);
     put '%macro1(inputtable=A, outputtable = B_P, size=1000,part=' part')' ;
  end;
  stop;
run;
%include code / source2 ;

 

I have a table A which create several B tables named B_P0, B_P2,...,B_P(n-1)

I would like to create in the same datastep the table C as an union of all B_P tables, and then delete B_P tables.

 

How can I do this?

 

Thanks

 

2 REPLIES 2
Planck
Obsidian | Level 7

I tried to do something like that:

 

%macro union(partnumber);
data C; set B_P0; run;
%do part=1 %to &partnumber;
PROC APPEND BASE= C DATA= B_P.part; RUN;
%end;
%mend;

filename code temp;
data _null_;
  set A nobs=nobs ;
  file code ;
  nb = int(nobs/1000);
  do part=0 to int(nobs/1000);
     put '%macro1(inputtable=A, outputtable = B_P, size=1000,part=' part')' ;
  end;
  stop;
  put '%union(partnumber = ' nb')' ;
run;
%include code / source2 ;

But apparantly it is not working. 😞

 

It is running for a very long time without answers.

s_lassen
Meteorite | Level 14

Planck,

It is very hard to tell what is wrong with your code when we do not know what the %MACRO1 macro is supposed to do.

 

When you say it is running for a very long time without answers. does that mean that you never see the "source2" code in the log? In that case it seems to mean that the first call of %MACRO1 is somehow stuck and just hangs.

 

What happens if you open the generated program in an editor and submit line by line? That is the great advantage of generating a file instead of using CALL EXECUTE or such: when developing/testing, you can take a good, long look at the generated code before submitting it, and you can submit it one step at a time and check the output before you proceed.

 

BTW, you put the 

  put '%union(partnumber = ' nb')' ;

 after the "stop;" statement in your datastep, meaning that it does not get written to the code file.

 

Regards,

Søren

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1064 views
  • 0 likes
  • 2 in conversation