BookmarkSubscribeRSS Feed

Hi,

 

I have this part of a SAS Macro

 

%let runmonth=%sysfunc(intnx(month,%sysfunc(today()),-1),yymmn6.); /*Curr Month*/

%let lastmonth=%sysfunc(intnx(month,%sysfunc(today()),-2),yymmn6.); /*Prev Month*/

%let runmonth2=%sysfunc(intnx(month,%sysfunc(today()),-1),yymmdd10.); /*Curr Month*/

%let HPIDate=%sysfunc(intnx(quarter,"&runmonth."d,0,e),yymmdd10.); /*last month of previous Qtr*/

 

and when I run the HPIDate, I get this error message

 

14 GOPTIONS ACCESSIBLE;

SYMBOLGEN: Macro variable RUNMONTH resolves to 201610

ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.

ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC

or %QSYSFUNC function reference is terminated.

15 %let HPIDate=%sysfunc(intnx(quarter,"&runmonth."d,0,e),yymmdd10.);

16

17 GOPTIONS NOACCESSIBLE;

18 %LET _CLIENTTASKLABEL=;

19 %LET _CLIENTPROJECTPATH=;

20 %LET _CLIENTPROJECTNAME=;

21 %LET _SASPROGRAMFILE=;

22

23 ;*';*";*/;quit;run;

24 ODS _ALL_ CLOSE;

25

26

27 QUIT; RUN;

28

 

How do I get around this please?

 

2 REPLIES 2
Kurt_Bremser
Super User

The literal "201610"d is not a valid date literal. '01oct2016'd would be one.

 

To make your life easier, I recommend to do all the calculations in a data _null_ step and use call symput() to create the macro variables.

 

And when I need a date for reference in a macro variable, I simply use the raw number:

%let runmonth=%sysfunc(today());

Can be used anywhere where a date is needed.

Kurt_Bremser
Super User

To create hpidate, I'd do

data _null_;
runmonth = intnx('month',today(),-1);
hpidate = intnx('quarter',runmonth,-1,'e');
call symput('hpidate',put(hpidate,best.));
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1229 views
  • 1 like
  • 2 in conversation