Hi,
I want to use the macro variable DATE defined below
%LET DATE = '29NOV2018'D;
to create another macro variable that looks like this.
%LET DATETIME = '2018-11-29 00:00:00.0000000';
How can I achieve this?
Thanks!
Since a date is a count of days, and a datetime a count of seconds, you only need to multiply with 86400 wherever you need the datetime, or use the dhms() function.
Note that your wanted value is useless except for display.
@pradark1 wrote:
Hi,
I want to use the macro variable DATE defined below
%LET DATE = '29NOV2018'D;
to create another macro variable that looks like this.
%LET DATETIME = '2018-11-29 00:00:00.0000000';
How can I achieve this?
Thanks!
Use DHMS function. Note the second parameter in SYSFUNC is the format. The default will be a datetime that's numeric, to have is shown as indicated you need to apply a format, in this case I've used datetime. Note that applying a display format makes it more difficult to use in the future because you need quotes and dt at the end, whereas the numerical variable will be interpreted correctly.
%let datetime = %sysfunc(dhms(&date., 0, 0, 0), datetime.);
%put &datetime.;
The
Your display format can be achieved with the e8601dt. format and filtering out the "T", or by rolling your own format with proc format.
And please note that not everybody here is male. Using "guys" when addressing our most prolific solution provider is sexist at best.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.