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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 371 views
  • 3 likes
  • 2 in conversation