cancel
Turn on suggestions
Showing results for
Search instead for
Did you mean:
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
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 !

0 Likes
1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

You want the TRANSLATE function, not TRANWRD.

%let Date_today=%sysfunc(translate(%sysfunc(today(),ddmmyy10.),"_","/"));
%put &=date_today;
--
Paige Miller
4 REPLIES 4
Diamond | Level 26

You want the TRANSLATE function, not TRANWRD.

%let Date_today=%sysfunc(translate(%sysfunc(today(),ddmmyy10.),"_","/"));
%put &=date_today;
--
Paige Miller
Barite | Level 11
Thank you!
0 Likes
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.

Barite | Level 11
Thank you, Tom !
0 Likes

sasinnovate.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just 495ドル!

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
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /