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.;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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