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!
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.