BookmarkSubscribeRSS Feed
alepage
Barite | Level 11
data test2;
PIT_day = intnx('day',(intnx('month',date(),-1,'e')),-2);
AUTH_DT = intnx('dtday',(intnx('dtmonth',datetime(),-0, 'b')),-3) +'20:00:00't ;
AUTH_DT2 = PIT_day +'20:00:00't ;
format pit_day date9. AUTH_DT2 auth_dt datetime19.;
run;

The PIT_day and AUTH_DT gives the expected values.

However, if I want to reuse the value of PIT_day like in AUTH_DT2, it does not give 29MAY2024:20:00:00

How could we do that ?

2 REPLIES 2
Kurt_Bremser
Super User

This cannot work:

AUTH_DT2 = PIT_day +'20:00:00't ;

SAS dates are counts of days, while times are counts of seconds; you are mixing apples and oranges here.

Use the DHMS function instead:

auth_dt2 = dhms(pit_day,20,0,0);
Tom
Super User Tom
Super User

If you want to convert a DATE value (number of days) into a DATETIME value (number of seconds) you could just multiply the value by the number of seconds in a day ('24:00:00't). 

datetime = date*'24:00:00't ;

But SAS also has a function that does that.  DHMS(days,hours,minutes,seconds).

datetime = dhms(date,0,0,0);

You could also just create a datetime value to begin with.

PIT_dt = intnx('dtday',(intnx('dtmonth',datetime(),-1,'e')),-2);
format pit_dt datetime19.;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 439 views
  • 2 likes
  • 3 in conversation