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

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.

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