BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ywon111
Quartz | Level 8

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.));

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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.;

View solution in original post

9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

I'm not sure what your desired result is here?

ywon111
Quartz | Level 8
Latest_month is a macro to get the previous month (e.g. 31OCT2021) and I am trying to get the day (31) and abbreviated month (Oct) based on this macro,.
PeterClemmensen
Tourmaline | Level 20

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.;
ErikLund_Jensen
Rhodochrosite | Level 12

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.;
ywon111
Quartz | Level 8
Thanks, all worked great.

Adding this into title for proc report also and looks like when export to excel then the space in between day, month and year disappeared (e.g. 31OCT2021) instead of 31 OCT 2021.

Any trick to fix this?

This is what I have

Title1 j=left "Graph1 blah blah blah as at &day &month &year";
proc report data=want
...
Kurt_Bremser
Super User

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.

ywon111
Quartz | Level 8

Thanks, that's exactly what I needed.

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @ywon111 

 

So you actually want 10 as day? 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1177 views
  • 0 likes
  • 4 in conversation