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

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2667 views
  • 2 likes
  • 3 in conversation