BookmarkSubscribeRSS Feed
Swathi12
Calcite | Level 5

Hi,

 

the below is a macro calling another macro.

 

%macro one;

data callinsertcustcomms;
set two;
length id $3000;


id = catx("|", ciskey, emailunsubscribeflag,datefirstjoined,tenure,tierid,commstypeid, commschannel,
PrevTierDataFlag,CustExpBal,MaxBankRewards,
CumRewardsValue,CalcItemsFlag,Misc1,Misc2,Misc3,Misc4,Misc5) ;


insertcustcomms = cats('%nrstr(%b('!!trim(id)!!'))');
put insertcustcomms;
call execute ( insertcustcomms ) ;

run;

%mend;
%one

 

%macro b(monthlyNL);
%put great;
%mend;

 

 

in the first macro the table callinsertcustcomms has 47708 rows.Ideally the macro b should be called 47708 times.

 

But it is called 47742 times.

 

Request your help!

2 REPLIES 2
Tom
Super User Tom
Super User

I do not see how it could call the macro more times than the number of observations in the input dataset, unless the macro calls itself.

 

Your macro %ONE does not appear to have any macro code in it. Why is it coded as a macro and not just a data step?

 

I find it much easier to use a PUT statement to write the code to a file and then %INCLUDE the file instead of using CALL EXECUTE.

That way you can run the step that generates the code and check the code before running it to make sure you have the code generation correct.

filename code temp;
data callinsertcustcomms;
  set two;
  length id $3000;
  id = catx("|", of 
    ciskey emailunsubscribeflag datefirstjoined tenure tierid
    commstypeid commschannel PrevTierDataFlag CustExpBal MaxBankRewards
    CumRewardsValue CalcItemsFlag Misc1-Misc5
    ) 
  ;
  file code ;
  put '%b(' id ')';
run;
%include code / source2;

A process that calls a macro 47 thousand times is probably not a good process.

What is it that you are actually trying to do? Does it even require any macros?

 

ballardw
Super User

Please describe how you know that the macro is called 47742 times.

 

Since your demonstrated macro B basically does nothing I doubt that you counted "great" 47742 times in the log.

 

I might suspect that your macro B has some %if code in there and the stuff in the parameter is sometimes hitting a boundary condition or two that are using LE and GE with some equal values where not expected causing a few records to do *something* more than once for some values of ID.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 527 views
  • 0 likes
  • 3 in conversation