BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I would like to display the today date as DD_MM_YY. I apply this code :

%let Date_today=%sysfunc(tranwrd(%sysfunc(today(),ddmmyy10.),"/","_"));

But I have as result DD/MM/YY.

 

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You want the TRANSLATE function, not TRANWRD.

 

 

%let Date_today=%sysfunc(translate(%sysfunc(today(),ddmmyy10.),"_","/"));
%put &=date_today;

 

 

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You want the TRANSLATE function, not TRANWRD.

 

 

%let Date_today=%sysfunc(translate(%sysfunc(today(),ddmmyy10.),"_","/"));
%put &=date_today;

 

 

 

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
Thank you!
Tom
Super User Tom
Super User

Because the three byte string you asked TRANWRD to change did not appear, so it made no changes.

1    %put %sysfunc(tranwrd(%sysfunc(today(),ddmmyy10.),"/","_"));
16/11/2025

You could remove the quote characters from the strings.

2    %put %sysfunc(tranwrd(%sysfunc(today(),ddmmyy10.),/,_));
16_11_2025

You could switch to using TRANSLATE, which replaces individual bytes. Remember that the order of the TO and FROM arguments is reversed.

3    %put %sysfunc(translate(%sysfunc(today(),ddmmyy10.),_,/));
16_11_2025

Note if you include multiple bytes in the FROM and TO arguments then the bytes are paired up by their position in the TO and FROM arguments.  As long as you use the same quotes in both TO and FROM (or the source strings does not have any quotes to translate) then you can get away with adding quotes around the characters you want translated.

4    %put %sysfunc(translate(%sysfunc(today(),ddmmyy10.),"_","/"));
16_11_2025

 Which could be useful when the values contain commas or other special characters since then you can avoid having to use macro quoting.

5    %put %sysfunc(translate(%sysfunc(today(),ddmmyy10.),",","/"));
16,11,2025

And finally if you plan to use this underscore delimited string in file names the you should use YMD order instead so that the names will sort properly.

6    %put %sysfunc(translate(%sysfunc(today(),yymmdd10.),_,-));
2025_11_16

And as an added bonus you avoid people confusing October twelfth for the tenth of December. 

 

SASdevAnneMarie
Barite | Level 11
Thank you, Tom !
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
  • 4 replies
  • 252 views
  • 4 likes
  • 3 in conversation