BookmarkSubscribeRSS Feed
Hessa
Calcite | Level 5

Capture.PNG

 

Got this error from this Macro:

 

data _null_;

call symputx('L12MODATE',intnx('month',today(),-12,'E'));

call symputx('L1MODATE',intnx('month',today(),-1,'E'));

call symput('testADJL12M',put(&L12MODATE,Monyy7.));

run;

 

 

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

It won't resolve in the same data step. Put it in a new data step. (Or just use the formula for &L12MODATE instead of &L12MODATE) (Or, make L12MODATE a data step variable and then you can use it wherever you want in the data step)

--
Paige Miller
Kurt_Bremser
Super User

Just to clarify further:

&L12MODATE is resolved while the code is being fetched for compilation. call symput() executes after compilation, when the compiled data step is run.

If you want to keep values across dataset observations (and therefore data step iterations), you can use the symget() function to retrieve macro variables set with call symput() in the same data step. But before doing this, look if other methods (retained variables, hash objects, temporary arrays or the lag() function) might not do the same, and avoid the macro detour.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Or just do it using code:

data _null_;
  call symputx('L12MODATE',intnx('month',today(),-12,'E'));
  call symputx('L1MODATE',intnx('month',today(),-1,'E'));
  call symput('testADJL12M',put(intnx('month',today(),-12,'E'),Monyy7.));
run;

Or, to add, you could just use the base SAS code you give above in your code rather than use macro variables at all.  I.e. as a programmer I know what:

intnx('month',today(),-12,'E')

means, however (and for the sake of a few typing characters):

&L12MODATE.

Is totally meaningless to me, and means I then have to spend further time decoding what is happening - this is what obfuscation does. 

data_null__
Jade | Level 19

You need SYMGET(N).

 

27         data _null_;
28            call symputx('L12MODATE',intnx('month',today(),-12,'E'));
29            call symputx('L1MODATE',intnx('month',today(),-1,'E'));
30            call symputx('testADJL12M',put(symgetn('L12MODATE'),Monyy7.));
31            run;

    

32         %put &=L12modate &=testADJL12M;
L12MODATE=20788 TESTADJL12M=NOV2016
PaigeMiller
Diamond | Level 26

@data_null__ wrote:

You need SYMGET(N).

 

27         data _null_;
28            call symputx('L12MODATE',intnx('month',today(),-12,'E'));
29            call symputx('L1MODATE',intnx('month',today(),-1,'E'));
30            call symputx('testADJL12M',put(symgetn('L12MODATE'),Monyy7.));
31            run;

    

32         %put &=L12modate &=testADJL12M;
L12MODATE=20788 TESTADJL12M=NOV2016

I'm sorry, all this symget or symgetn is completely unnecessary and overcomplicates things. 

 

data _null_;
    l12modate=intnx('month',today(),-12,'E');
    call symputx('L12MODATE',l12modate);
    call symputx('L1MODATE',intnx('month',today(),-1,'E'));
    call symputx('testADJL12M',put(l12modate,Monyy7.));
run;

 

 

--
Paige Miller

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
  • 5 replies
  • 1403 views
  • 6 likes
  • 5 in conversation