DATA Step, Macro, Functions and more

How to get the end of previous month in a macro variable using %sysfunc?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 122
Accepted Solution

How to get the end of previous month in a macro variable using %sysfunc?

Hi,

 

I am trying to get the end of previoius month using this macro, but guess I am missing something.

 

%let date=%sysfunc(intnx(month, %sysfunc(today()),-1,'e'), yymmdd10.);
%put &date.;

 

Please help.

 

 


Accepted Solutions
Solution
‎11-11-2016 04:28 PM
Frequent Contributor
Posts: 122

Re: How to get the end of previous month in a macro variable using %sysfunc?

Posted in reply to data_null__

All Replies
Super User
Posts: 5,441

Re: How to get the end of previous month in a macro variable using %sysfunc?

What do you get?
Data never sleeps
Frequent Contributor
Posts: 122

Re: How to get the end of previous month in a macro variable using %sysfunc?

I get the below message:

 

67 %let date=%sysfunc(intnx(month, %sysfunc(today()),-1,'e'), yymmdd10.);
WARNING: Argument 4 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function
is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
result of the operations have been set to a missing value.
68 %put &date.;

 

Not sure what I need to do or missingSmiley Sad

Trusted Advisor
Posts: 1,586

Re: How to get the end of previous month in a macro variable using %sysfunc?

Without %sysfunc you can calculate date with data step inside the macro program, just as:

         data _NULL_;

             date = today() - day(today());

             call symput('date', left(date));

       run;

 

with %sysfunc,you can try:

        %let date = %sysfunc( today() - day(today()) );

Respected Advisor
Posts: 3,799

Re: How to get the end of previous month in a macro variable using %sysfunc?

Get rid of the quote E not 'E'
Solution
‎11-11-2016 04:28 PM
Frequent Contributor
Posts: 122

Re: How to get the end of previous month in a macro variable using %sysfunc?

Posted in reply to data_null__

Thank you!

Frequent Contributor
Posts: 111

Re: How to get the end of previous month in a macro variable using %sysfunc?

%let date=%sysfunc(intnx(month, %sysfunc(today()),-1,e), yymmdd10.);
%put &date.;

 

Just remove the single quotation markes from e

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1847 views
  • 0 likes
  • 5 in conversation