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
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at 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 2025: Call for Content

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!

Submit your idea!

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