BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
richaemi
Fluorite | Level 6

I am trying to find the difference in minutes between two events. I have two variables for time and two variables for dates. I first tried both the INTCK function and FLOOR function, which worked well to find the difference in minutes between my time variables. However, this does not account for date changes.

 

For example, in finding the time between Onset and Randomization:

For Subject 1 - 

OnsetDate is 2011-05-15 and OnsetTime is 15:00:00. 

RandomizationDate is 2011-05-15 and RandomizationTime is 17:36:00.

This leaves 156 minutes between Onset and Randomization.

For Subject 2 - 

OnsetDate is 2011-06-27 and OnsetTime is 21:55:00.

RandomizationDate is 2011-06-28 and RandomizationTime is 00:35:00.

I need a function that can account for this date change when finding the time difference.

 

Any advice is much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Create complete timestamps (datetime values) out of your variables first:

onset_ts = dhms(onset_date,0,0,onset_time);

Then you can use intck to find the difference:

diff_minutes = intck('minute',onset_ts,rand_ts);

Or do a simple calculation:

diff_minutes = (rand_ts - onset_ts) / 60;

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Create complete timestamps (datetime values) out of your variables first:

onset_ts = dhms(onset_date,0,0,onset_time);

Then you can use intck to find the difference:

diff_minutes = intck('minute',onset_ts,rand_ts);

Or do a simple calculation:

diff_minutes = (rand_ts - onset_ts) / 60;

 

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

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
  • 1 reply
  • 837 views
  • 3 likes
  • 2 in conversation