BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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
MonaMir
Calcite | Level 5

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.

 

 

Tom
Super User Tom
Super User

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?

MonaMir
Calcite | Level 5

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.),'

Tom
Super User Tom
Super User

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: 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
  • 7881 views
  • 3 likes
  • 4 in conversation