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
BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1257 views
  • 3 likes
  • 5 in conversation