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

Hello

Today is 13 April 2018

I want to get date one month back...(13 Mar 2018)

What is wrong in the code that the result is 01Mar2018

%let dts = "%sysfunc(today(),date9.)"d;
%put &dts;/*"12APR2019"d*/
%let w = "%sysfunc(intnx(MONTH,&dts,-1),date9.)"d;
%put &w;/*"01MAR2019"d*/
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
117  %let dts = %sysfunc(today());
118  %put &dts;/*"12APR2019"d*/
21651
119  %let w = %sysfunc(intnx(MONTH,&dts,-1,s),date9.);
120  %put &w;
12MAR2019

 

@Ronein 

For calculations, plz keep the Date value as numbers and avoid formats or using string literals.

If you want, just format the final needed result as show above.

 

Plus you need s option to get the same value of the previous month

 

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
117  %let dts = %sysfunc(today());
118  %put &dts;/*"12APR2019"d*/
21651
119  %let w = %sysfunc(intnx(MONTH,&dts,-1,s),date9.);
120  %put &w;
12MAR2019

 

@Ronein 

For calculations, plz keep the Date value as numbers and avoid formats or using string literals.

If you want, just format the final needed result as show above.

 

Plus you need s option to get the same value of the previous month

 

 

Tom
Super User Tom
Super User

Nothing to do with macro.

You need set the last parameter for the INTNX() function to SAME. If you don't specify a value the default is to use BEGINNING.

%let w = "%sysfunc(intnx(MONTH,&dts,-1,s),date9.)"d;

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
  • 2 replies
  • 2229 views
  • 2 likes
  • 3 in conversation