BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
Hi,
How do I change the format of &sysdate from 14JUL10 to July 14, 2010 in the code below?

data _null_;
dcl odsout obj();
obj.table_start(name: "Date",
obj.row_start();
obj.format_cell(data: "Data updated &sysdate.",
obj.row_end();

Thank you.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Create your own &MY_SYSDATE by using the &SYSDATE9 variable, converted to a SAS NUMERIC DATE, using INPUT, and follow that with a suitable PUT to re-format to your own date-variable value. Explore using %SYSFUNC(...) along with suitable SAS functions to do the data conversions, mentioned above.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
> Create your own &MY_SYSDATE by using the &SYSDATE9
> variable, converted to a SAS NUMERIC DATE, using
> INPUT, and follow that with a suitable PUT to
> re-format to your own date-variable value. Explore
> using %SYSFUNC(...) along with suitable SAS functions
> to do the data conversions, mentioned above.
>
> Scott Barry
> SBBWorks, Inc.

gzr2mz39

As Scott suggests - use %sysfunc()

The common route to reformat dates, uses the second parameter of %sysfunc() - a format for the results when the first parameter is a numeric function {like inputN() }

"Today" is much easier, than yesterday, which I would format like
%put yesterday was %sysfunc( intnx(day, "&sysdate9"d, -1), weekdate ) ;

The simpler equivalent for today (needing no intnx() function )
%put today is %sysfunc( putN("&sysdate9"d, weekdate ) ) ;
Alternatively, when using a SAS server which may have started before today (SAS session start time provides the underlying value in &sysdate and &sysdate9), use the today() function like
%put today is %sysfunc( today(), weekdate ) ;

When presenting timestamps, I like the SAS Title style :
%put now it is %sysfunc( datetime(), twmdy ) ;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I just noticed the OP is using a DATA step, so it's not necessary to use the character-string for &SYSDATE or &SYSDATE9 -- you can get the current date using one of several techniques, such as TODAY() function or a RETAIN SAS variable assigned to a constant "&SYSDATE9"D, and the use your DATA step variable to assign a date character-string in whatever format you choose, using a SAS output FORMAT. Given the code initially posted, no %SYSFUNC(...) is even needed.

Scott Barry
SBBWorks, Inc.

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
  • 6136 views
  • 0 likes
  • 3 in conversation