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

I have a SAS program that creates an Excel file that includes the current date as part of the file name. The data in the file is from the prior month.  How do I change the date to show the prior month in a MM-YYYY format?

 

Here is my current code that names the Excel file:

 

%let file1=/saswork/Corporate/Marketer_Services_Reporting/Data/_Scheduled Reports/CLASS Monthly/CLASS Completions-%QSYSFUNC(DATE(),worddate18.).xlsx;


ods excel file="&file1";

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
%SYSFUNC(intnx(month, %sysfunc(DATE()), -1, e), mmyyd6.)

View solution in original post

2 REPLIES 2
Reeza
Super User
%SYSFUNC(intnx(month, %sysfunc(DATE()), -1, e), mmyyd6.)
PaigeMiller
Diamond | Level 26
%let file1=/saswork/Corporate/Marketer_Services_Reporting/Data/_Scheduled Reports/CLASS Monthly/CLASS Completions-%sysfunc(today(),mmyyd7.).xlsx;

Although I think the formatting of MM-YYYY is a very poor choice because if you try to sort these files, they don't wind up in chronological order, they wind up with all the January files first regardless of year, and all the February files ...

 

Whereas yyyy-mm would always sort in chronological order.

--
Paige Miller

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
  • 2 replies
  • 997 views
  • 5 likes
  • 3 in conversation