Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

work out previous month

Status
Not open for further replies.

mlaunce

Programmer
Dec 7, 2005
1
US
Hi,

I'm using the following code to produce MMMYYYY as at today's date and it works fine.

%let monyear=%substr(%sysfunc(today(), date9.),3,7);
%put &monyear;
DEC2005

Trouble is, I need to modify the code to give the previous month in the macro output, so today it would give
NOV2005.

Any help would be much appreciated!
 
mlaunce,

I have a macro solution. its extremely messy, but here it is:

Code:
%let monyear =%sysfunc(putn(%sysfunc(mdy(%sysfunc(putn( %eval(%sysfunc(month(%sysfunc(date())) )-1),8.)),
            1,%sysfunc(putn(%sysfunc(year(%sysfunc(date())) ),8.)))),monyy7.));

Let me know if it works for you, you may have to adjust it.
Klaz
 
I have found an even shorter code string that should also work.


Code:
%let monyear = %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(date()),-1)),monyy7.));

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top