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*/
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
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
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
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.