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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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