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?
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.
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;
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.