Hi
I am using a Date prompt to get a month and year (the macro has the values in DDMMMYY format eg: 01JAN2022).
Can someone help me to find a way to obtain the next month and the previous month?
Thanks in advance
Here is one way that is easy to follow:
%let MyDate = 01Jan2022;
data _null_;
Next_Month = intnx('MONTH', "&MyDate"d, 1, 'BEGINNING');
Last_Month = intnx('MONTH', "&MyDate"d, -1, 'BEGINNING');
format Next_Month Last_Month date9.;
call symputx('Next_Month', put(Next_Month,date9.));
call symputx('Last_Month', put(Last_Month,date9.));
put _all_;
run;
%put Next_Month = &Next_Month;
%put Last_Month = &Last_Month;
Here is one way that is easy to follow:
%let MyDate = 01Jan2022;
data _null_;
Next_Month = intnx('MONTH', "&MyDate"d, 1, 'BEGINNING');
Last_Month = intnx('MONTH', "&MyDate"d, -1, 'BEGINNING');
format Next_Month Last_Month date9.;
call symputx('Next_Month', put(Next_Month,date9.));
call symputx('Last_Month', put(Last_Month,date9.));
put _all_;
run;
%put Next_Month = &Next_Month;
%put Last_Month = &Last_Month;
Thank you very much! It worked 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.