BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

 %let runDate=%sysfunc(putn(%sysfunc(date()), yymmddn8.)); %put &runDate; I want to format the date like 3_11_2025

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

It doesn't exist out-the-box, but you can roll out your own using Proc Format

 

proc format; 
   picture dtfmt other = '%m_%D_%Y' (datatype=date);
run;

%let runDate=%sysfunc(putn(%sysfunc(date()), dtfmt.)); 
%put &=runDate.;
Tom
Super User Tom
Super User

You  don't need a FORMAT.  Use one of the existing formats and then use TRANSLATE() to replace the delimiters.

1    %let rundate=%sysfunc(date(),yymmddd10.);
2    %put &=rundate;
RUNDATE=2025-03-11
3    %let rundate=%sysfunc(translate(&rundate,_,-));
4    %put &=rundate;
RUNDATE=2025_03_11

PS Do not make strings with dates in MDY or DMY order.  In addition to the risk of confusing half of your audience they will not sort properly.

 

If you might run the job more than once a day you could use DATETIME() function and formats instead.  For example E8601DT16. will display YMDHM.

1    %let rundate=%sysfunc(translate(%sysfunc(datetime(),e8601dt16.),___,-T:));
2    %put &=rundate;
RUNDATE=2025_03_11_18_48
Ksharp
Super User

Or just simply list them all.

%let runDate=%sysfunc(date(),month2.)_%sysfunc(date(),day2.)_%sysfunc(date(),year4.);

%put &=runDate ;
7    %let runDate=%sysfunc(date(),month2.)_%sysfunc(date(),day2.)_%sysfunc(date(),year4.);
8
9    %put &=runDate ;
RUNDATE=3_12_2025

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 742 views
  • 4 likes
  • 4 in conversation