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;
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)
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.
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.
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
@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;
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!
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.