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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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