BookmarkSubscribeRSS Feed
SAS09
Calcite | Level 5

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.

5 REPLIES 5
Quentin
Super User
39   %let medate=30MAY2014;
40   %put %sysfunc(intnx(month,"&medate"d,-12),yymmn4);
1305
SAS09
Calcite | Level 5

Thank you - this is helpful!  However I need for this value to be in a character format.  Any ideas?

CTorres
Quartz | Level 8

%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;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2120 views
  • 3 likes
  • 5 in conversation