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;

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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