%let runDate=%sysfunc(putn(%sysfunc(date()), yymmddn8.)); %put &runDate; I want to format the date like 3_11_2025
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.;
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
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
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!
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.