DATA Step, Macro, Functions and more

SAS Macro error

Reply
anonymous_user
Posts: 0

SAS Macro error

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?

 

Super User
Posts: 7,809

Re: SAS Macro error

Posted in reply to anonymous_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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,809

Re: SAS Macro error

Posted in reply to anonymous_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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 2 replies
  • 172 views
  • 1 like
  • 2 in conversation