I have a macro to get the latest month as below and trying to use this to get day and month.
%let Latest_month = %sysfunc(intnx(month, %sysfunc(today()), -1, END), date9.);;
This is what I have tried:
%let day = %sysfunc(month("&Latest_month"d),DAYw.);
%let sysmonth= %sysfunc(put(month("&Latest_month "d),monname3.));
Try this
%let Latest_month = %sysfunc(intnx(month, %sysfunc(today()), -1, END), date9.);
%let day = %sysfunc(month("&Latest_month"d));
%let month = %sysfunc(putn("&Latest_month"d, monname3.));
%put &day.;
%put &month.;
I'm not sure what your desired result is here?
Try this
%let Latest_month = %sysfunc(intnx(month, %sysfunc(today()), -1, END), date9.);
%let day = %sysfunc(month("&Latest_month"d));
%let month = %sysfunc(putn("&Latest_month"d, monname3.));
%put &day.;
%put &month.;
Hi @ywon111
Try this. The main difference is that day and not month is assigned to the &day macro variable.
%put %sysfunc(propcase(%sysfunc(putn(&Latest_month,date5.))));
%let day = %sysfunc(day(&Latest_month));
%let month = %sysfunc(putn(&Latest_month, monname3.));
%put &day.;
%put &month.;
Please post your report code, from ODS EXCEL to ODS EXCEL CLOSE.
Is this for display purposes?
If yes, do this:
%let Latest_month = %sysfunc(intnx(month,%sysfunc(today()),-1,e));
%let day = %sysfunc(putn(&Latest_month.,day2.));
%let sysmonth = %sysfunc(putn(&Latest_month.,monname3.));
%put &=day. &=sysmonth.;
Log:
69 %let Latest_month = %sysfunc(intnx(month,%sysfunc(today()),-1,e)); 70 %let day = %sysfunc(putn(&Latest_month.,day2.)); 71 %let sysmonth = %sysfunc(putn(&Latest_month.,monname3.)); 72 %put &=day. &=sysmonth.; DAY=31 SYSMONTH=Oct
Note that macro variables used in calculations need no formats, see Maxim 28.
Thanks, that's exactly what I needed.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.