DATA Step, Macro, Functions and more

change format of &sysdate

Reply
Regular Contributor
Posts: 199

change format of &sysdate

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: change format of &sysdate

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.
Valued Guide
Posts: 2,177

Re: change format of &sysdate

> 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 ) ;
Super Contributor
Super Contributor
Posts: 3,174

Re: change format of &sysdate

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.
Ask a Question
Discussion stats
  • 3 replies
  • 226 views
  • 0 likes
  • 3 in conversation