BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gil_
Quartz | Level 8
I have a table with a datetime field i need to get to pull whst the entry was 6 hrs ago

Id. Datetime. Balance
. 21sep2018:12:22:30. 100
B2. 21sep2018:10:22:30. 189
A6. 21sep2018:12:09:30. 65
Whst i want is to pull report showing what they did 6 hrs ago

Id. Datetime. Balance
. 21sep2018:06:22:30. 233
B2. 21sep2018:04:22:30. 35
A6. 21sep2018:03:09:30. 64
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You can use function INTCK to check the time interval between two dates / datetimes / times:

 

SYNTAX:

INTCK(interval<multiple><.shift-index>, from, to)

 

You should define interval as "hour". Then check the interval is it less or equal to 6.

View solution in original post

5 REPLIES 5
ballardw
Super User

@Gil_ wrote:
I have a table with a datetime field i need to get to pull whst the entry was 6 hrs ago

Id. Datetime. Balance
. 21sep2018:12:22:30. 100
B2. 21sep2018:10:22:30. 189
A6. 21sep2018:12:09:30. 65
Whst i want is to pull report showing what they did 6 hrs ago

Id. Datetime. Balance
. 21sep2018:06:22:30. 233
B2. 21sep2018:04:22:30. 35
A6. 21sep2018:03:09:30. 64

Exactly to the second (or fraction thereof) 6 hours ago? Or "closest to 6 hours" (might be 5 hours and 58 minutes). Or the closest at least six hours ago (six hours and three minutes?

Gil_
Quartz | Level 8
Yes as close as 6 hrs
SASKiwi
PROC Star

You need to be more precise explaining your requirements.

 

For example, for each ID value get the row with the datetime that is closest to being no more than 6 hours prior to the time the query runs. Does this agree with what you want or not?

mkeintz
PROC Star

What do you want to do with the first 5-6 hours of data records?   How close to 6 hours prior to the record-in-hand  must the target observation be?  What is the sort order of incoming data, and how big is it?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Shmuel
Garnet | Level 18

You can use function INTCK to check the time interval between two dates / datetimes / times:

 

SYNTAX:

INTCK(interval<multiple><.shift-index>, from, to)

 

You should define interval as "hour". Then check the interval is it less or equal to 6.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 1674 views
  • 0 likes
  • 5 in conversation