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.

 

Review SAS CI360 now.png

 

Want to review SAS CI360? G2 is offering a gift card or charitable donation for each accepted review. Use this link to opt out of receiving anything of value for your review.

 

 

 

 

SAS Customer Intelligence 360

Get started with CI 360

Review CI 360 Release Notes

Open a Technical Support case

Suggest software enhancements

Listen to the Reimagine Marketing podcast

Assess your marketing efforts with a free tool

 

Training Resources

SAS Customer Intelligence Learning Subscription (login required)

Access free tutorials

Refer to documentation

Latest hot fixes

Compatibility notice re: SAS 9.4M8 (TS1M8) or later

 

 

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.

Review SAS CI360 now.png

 

Want to review SAS CI360? G2 is offering a gift card or charitable donation for each accepted review. Use this link to opt out of receiving anything of value for your review.

 

 

 

 

SAS Customer Intelligence 360

Get started with CI 360

Review CI 360 Release Notes

Open a Technical Support case

Suggest software enhancements

Listen to the Reimagine Marketing podcast

Assess your marketing efforts with a free tool

 

Training Resources

SAS Customer Intelligence Learning Subscription (login required)

Access free tutorials

Refer to documentation

Latest hot fixes

Compatibility notice re: SAS 9.4M8 (TS1M8) or later

 

 

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