Hi
I am using macro code to calculated sas date of two months before &start
%let start=1901;
%let start2=%sysfunc(intnx('month',input("&start",yymmn4.),-2,'b'));
%put &start2;
I get an error
ERROR: Required operator not found in expression: input("1901",yymmn4.)
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.
Every call of a data step function in a macro statement needs a %sysfunc() around it, and the put() and input() functions cannot be used in %sysfunc, so you need to use inputn():
%let start=1901;
%let start2=%sysfunc(intnx(month,%sysfunc(inputn(&start.,yymmn4.)),-2,b));
%put &start2;
Log:
24 %let start=1901; 25 %let start2=%sysfunc(intnx(month,%sysfunc(inputn(&start.,yymmn4.)),-2,b)); 26 %put &start2; 21489
Every call of a data step function in a macro statement needs a %sysfunc() around it, and the put() and input() functions cannot be used in %sysfunc, so you need to use inputn():
%let start=1901;
%let start2=%sysfunc(intnx(month,%sysfunc(inputn(&start.,yymmn4.)),-2,b));
%put &start2;
Log:
24 %let start=1901; 25 %let start2=%sysfunc(intnx(month,%sysfunc(inputn(&start.,yymmn4.)),-2,b)); 26 %put &start2; 21489
I am trying to do the same but I run into issues 😞 :
%LET TD=%sysfunc(today());
%put &TD;
%Let timtt= %sysfunc(intck('month',&TD,-1,'b'));
%put &=timtt;
LOG:
%Let timtt= %sysfunc(intck('month',&TD,-1,'b'));
29 %put &=timtt;
TIMTT=.
So it spits out a "." . I have tried %Let timtt= %sysfunc(intck('month',&TD,-1,'b'),date9.); and still same thing. I have also removed the ' ' from 'month' and 'b' but still same thing.
Please assist.
To the macro processor everything is text, so quote characters are just part of the text. The INTNX() function knows about the MONTH interval but it knows nothing about an interval named 'MONTH'. Or target location of 'B'.
The INTCK() function allows last argument to be either C or D.
Did you mean to call the INTNX() function instead?
Thank you. rookie mistake (blushing). but now I want to use CAT and I run into issues. I want to create '01FEB2021'd with the %let and %sysfunc but it seems that the %sysfunc inside the Cat function doesn't get recognized and I get the following result as if it just cats the %sysfunc and rest together:
%Let timtet=%sysfunc(cat(',%sysfunc(intnx(month,&TD,-1,b),date9.),'));
%put &=timtet;
LOG:
%Let timtet=%sysfunc(cat(',%sysfunc(intnx(month,&TD,-1,b),date9.),'));
29 %put &=timtet;
TIMTET=',%sysfunc(intnx(month,&TD,-1,b),date9.),'
Why would you ever need to use CAT() in macro code? Just expand the values where you want them.
What are you trying to do? If you want to make a date literal use double quotes so the macro function calls are processed. Strings in single quote (which your code is creating by accident) are ignored by the macro processor.
%Let timtet="%sysfunc(intnx(month,&TD,-1,b),date9.)"d;
%put &=timtet;
But why bother? SAS language does not care whether you give it "01FEB2021"d or 22312, they both represent the same number of days since 1960.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.