I am trying to create a macro variable that will contain the prior year and same month based on a current date. For example if the current date is 30MAY2014 I wiould like to get 1305. However I keep getting an error with the following
:
%let medate=30MAY2014;
%Let Prior_Year=%sysfunc(cats(%substr(putc(%Sysfunc(year("&medate"d)),4.),3,2)-1,putc(%sysfunc(month("&medate"d)),z2.)));
The error I am getting is the following:
ERROR: Required operator not found in expression: putc(5,z2.)
I would really appreciate any suggestions on how I can fix this.
39 %let medate=30MAY2014; 40 %put %sysfunc(intnx(month,"&medate"d,-12),yymmn4); 1305
Thank you - this is helpful! However I need for this value to be in a character format. Any ideas?
%let medate=30MAY2014;
%let want=%sysfunc(intnx(month,"&medate"d,-12),yymmn4);
The value of macrovariable &want is already text.
data test;
char="&want";
num=&want;
run;
Well:
%let medate=30MAY2014;
data _null_;
call symput('prior_year',put(intnx('month',"&medate"d,-12),yymmn4.));
run;
%put &prior_year;
But my question would be, why not just use the calculation where you need it, no need to go creating new variables for it?
Assigning the value to a macro variable causes the intnx (or whatever method one uses) to be executed only once. Putting it into the later data step causes it to be executed with every iteration. The old-hand programmer in me cringes at that.
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.