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.