BookmarkSubscribeRSS Feed
badnash_2000
Calcite | Level 5

Hi,

After looking at lot of videos and reading through i am struggling to find answer to my query.

 

I am using SAS EG 8.3 and looking  to create a variable from an existing date and time variable for example variable is submission_date and stores '20Jan2023:15:30:33'.

 

I want the new variable to look at reports from day before yesterday 19:00 onwards, from the example above if i am running the code on 20th Jan then it should pull up records from 18Jan2023 19:00:00 onwards.

 

I am going to be running this report everyday and need the time fixed from 19:00 but not the date (as should always pull data from day before yesterday 19:00 onwards)

 

Any help and guidance will be highly appreciated and apologies for the repetition.

 

Thanks.

1 REPLY 1
ballardw
Super User

 

If the value is a SAS datetime value, meaning that it is numeric and has, apparently, a datetime18. format then you are looking for two functions. The INTNX function is used to change a value by a given interval

Intnx('dtday',submission_date,-1,'B') will return the beginning of the previous day (dtday means the interval is a day for a datetime variable), the -1 says "the interval before the submission_date, and the 'B' is return the beginning date.

 

so

intnx('hour',Intnx('dtday',submission_date,-1,'B'),19) will advance the result 19 hours and return the the datetime you want for comparison.

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 376 views
  • 0 likes
  • 2 in conversation