BookmarkSubscribeRSS Feed
RDS2020
Calcite | Level 5

Hi,

I am doing below for today's time and date. 

%let dt1= %sysfunc(putn(%eval(%sysfunc(today())-1),datetime.));

%put &dt1;

 

This is showing below date - 01JAN60:06:13:04

 

How can i get current TIME that also with leading zero in case it is single digit.

 

Thanks

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Use format date. instead of datetime.

--
Paige Miller
RDS2020
Calcite | Level 5

Thanks for replying. What about the Time part of it . I would need time part with leading zero if its single digit

PaigeMiller
Diamond | Level 26
%let dt1= %sysfunc(putn(%eval(%sysfunc(today())-1),datetime.));

There is no time associated with today()

 

Or, trivially, the time associated with today() is 00:00:00.

 

So what do you want from today()?

--
Paige Miller
Kurt_Bremser
Super User

Dates are counts of days, while times and datetimes are counts of seconds. With 1960-01-01T00:00:00 as the zero point, today's date value (22385) will show up as a datetime sometime on 1960-01-01.

 

How you format the value (or not) depends on the further use. If you do not need it for display, the raw value is best, as you can then use the macro variable without further ado:

%let dt1=%sysevalf(%sysfunc(datetime())-86400);

%put &=dt1.;

data want;
set have;
if datetimevalue le &dt1.;
run;

With DATETIME(), you will get time down to microseconds, so you need to use %SYSEVALF to cope with the fraction.

Tom
Super User Tom
Super User

TODAY() is just an alias for DATE() which returns a date value (number of days) not a datetime value (number of seconds).

 

To get the current datetime value use DATETIME() function instead of DATE() function.  To have the string formatted properly use at least a width of 19 in the format specification, otherwise you will get only two digits for the year.

%let dt1= %sysfunc(intnx(dtday,%sysfunc(datetime()),-1,s),datetime19.);

To get the current time of day (seconds since midnight) use the TIME() function.  To format it with leading zeros use the TOD format.

 

How to improve email deliverability

SAS' Peter Ansbacher shows you how to use the dashboard in SAS Customer Intelligence 360 for better results.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1616 views
  • 1 like
  • 4 in conversation