BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I define a global variable as follows:
%let todaydate=today();
and SAS assign a number to the 'todaydate'. Anyone knows whether it is possible for me to format the 'todaydate', e.g. ddmmyy or ddmonyy etc?
5 REPLIES 5
LinusH
Tourmaline | Level 20
Try

%let todaydate = %sysfunc(putn("&SYSDATE9"D,ddmmyy.));

Regards,
Linus
Data never sleeps
Cynthia_sas
Diamond | Level 26
Hi:
If you DO want to use the today() function instead of &SYSDATE9, you can use it directly in the %LET, and with the TODAY() function, a second argument is allowed for %SYSFUNC that formats the returned date:
[pre]
%let d1 = %sysfunc(today(),ddmmyy.);
%let d2 = %sysfunc(today(),worddate.);
%let d3 = %sysfunc(today(),mmddyy10.);
%let d4 = %sysfunc(putn("&sysdate9"d ,mmddyyp10.));
%let d5 = %sysfunc(putn('01Jan2008'd ,weekdate.));

%put d1= &d1;
%put d2= &d2;
%put d3= &d3;
%put d4= &d4;
%put d5= &d5;
[/pre]

cynthia
deleted_user
Not applicable
Hihi,

just tried but sas still assign some other number to the date..
Cynthia_sas
Diamond | Level 26
Hi:
&SYSDATE may not be the same date as TODAY(). Especially if your version of SAS is on a server that is not taken down often. Usually &SYSDATE is the date that the SAS session started...while TODAY() returns a value from the computer's "calendar/clock" functions.

Are you saying that today() does not return today's date????

[pre]
%let x = %sysfunc(today());
%let y = %sysfunc(today(),mmddyy10.);
[/pre]

If these statements do not produce the following results, then you should contact Tech Support for more help. (If you're on the other side of the international date line, of course, your date will be off from mine by a day.
[pre]
1 %let x = %sysfunc(today());
2 %let y = %sysfunc(today(),mmddyy10.);
3
4 %put *******x=&x y=&y;
*******x=17764 y=08/20/2008

[/pre]

Today's date in as a SAS number is 17764. With the mmddyy10. format applied, the macro variable &Y has a value of 08/20/2008.

cynthia
deleted_user
Not applicable
Hi..

I manage to get it already! Thanks so much for everybody's help.
\(^o^)/

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 4057 views
  • 1 like
  • 3 in conversation