<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculating difference in minutes between two time stamps in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874569#M345549</link>
    <description>&lt;P&gt;If you had actual TIMESTAMP value (timestamp is an alias for DATETIME) then you midnight problem goes away.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you get a better source that did not eliminate the DAY part from the DATETIME values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise just make up your own rule about when to consider the difference as negative versus close to 24 hours.&amp;nbsp; Kind of like the Year Cutoff that SAS uses for dealing with date values that have and the century removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you pick 30 minutes your code might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set question ;
  next_day = (Arrival_Time -TT_member_arrived) &amp;gt; '00:30:00't ;
  duration = next_day*'24:00:00't + TT_member_arrived - Arrival_Time;
  minutes = duration / 60 ;
  format duration time10. minutes comma6.2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1683584388432.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83732i797F44840A67A33C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1683584388432.png" alt="Tom_0-1683584388432.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 22:22:10 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-05-08T22:22:10Z</dc:date>
    <item>
      <title>Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874547#M345534</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question regarding time. formatted data and trying to calculate the minutes between the arrival of a patient and the arrival of members of their care team. Part of the issue is dealing with time that crosses midnight, and in some cases where the team member was present before the patient arrived.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is some example data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data question;
  input ID $ Arrival_Time time. TT_member_arrived time.  ;
format Arrival_Time time. TT_member_arrived time. ;
cards;
4077114 . 17:02:00
4077114 . 17:15:00
4077114 . 17:15:00
4077242 23:56:00 .
4077242 23:56:00 0:09:00
4077242 23:56:00 0:06:00
4077318 0:22:00 0:10:00
4077318 0:22:00 0:28:00
4077318 0:22:00 0:28:00
4077486 17:50:00 .
4077486 17:50:00 18:00:00
1776022 19:20:00 20:18:00
1776022 19:20:00 20:37:00
1776022 19:20:00 20:27:00
1776022 19:20:00 .
1776022 19:20:00 .
4078301 0:35:00 .
4078301 0:35:00 0:36:00
4078439 13:33:00 14:18:00
4078439 13:33:00 16:50:00
4078439 13:33:00 .
4078439 13:33:00 .
4078753 4:06:00 4:20:00
4078753 4:06:00 4:05:00
4078753 4:06:00 4:05:00
1813347 23:40:00 1:14:00
1813347 23:40:00 1:14:00
1813347 23:40:00 .
4079401 14:03:00 15:30:00
4079401 14:03:00 .
4079401 14:03:00 .
9980300 21:46:00 21:51:00
9980300 21:46:00 22:20:00
9980300 21:46:00 22:12:00
9980300 21:46:00 .
9980300 21:46:00 .
9980300 21:46:00 .
9980300 21:46:00 .
1975827 20:05:00 .
1975827 20:05:00 22:30:00
1975827 20:05:00 22:30:00
4079529 21:13:00 21:13:00
4079529 21:13:00 21:20:00
4079529 21:13:00 21:20:00
1828163 20:09:00 .
1828163 20:09:00 22:30:00
1828163 20:09:00 22:30:00
1828163 20:09:00 .
1676588 0:14:00 0:30:00
1676588 0:14:00 .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I attempted to use the following code to tabulate the number of minutes either (negative minutes for a team member being early) positive for the number of elapsed minutes until a member arrived.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    diff_in_min = intck("minute", Arrival_Time, TT_member_arrived);

  if TT_member_arrived lt Arrival_Time then duration=('24:00:00't-Arrival_Time)+TT_member_arrived;
  else duration=TT_member_arrived-Arrival_Time;
  
  duration_min = (duration/60);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a screenshot of the result:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="20obs.JPG" style="width: 584px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83727iA3FFF22ACE714128/image-size/large?v=v2&amp;amp;px=999" role="button" title="20obs.JPG" alt="20obs.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regardless of the method I tried either using intck or calculating duration didn't quite work. For instance row 5, I want the output to be the time between 23:56 and 0:09 or 13 minutes elapsed. Calculating the duration kind of worked except in cases where the team member was present before the patient arrived, for instance row 7, should be negative 12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 20:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874547#M345534</guid>
      <dc:creator>Shad</dc:creator>
      <dc:date>2023-05-08T20:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874550#M345536</link>
      <description>&lt;P&gt;Suggestion: don't eliminate the date from the time. If you have the actual dates and times, so the variables you read in are now valid SAS date/time variables, then INTCK ought to work to keep track of when the time crosses midnight into the next day, and you will get the proper result.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 20:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874550#M345536</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-08T20:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874569#M345549</link>
      <description>&lt;P&gt;If you had actual TIMESTAMP value (timestamp is an alias for DATETIME) then you midnight problem goes away.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you get a better source that did not eliminate the DAY part from the DATETIME values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise just make up your own rule about when to consider the difference as negative versus close to 24 hours.&amp;nbsp; Kind of like the Year Cutoff that SAS uses for dealing with date values that have and the century removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you pick 30 minutes your code might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set question ;
  next_day = (Arrival_Time -TT_member_arrived) &amp;gt; '00:30:00't ;
  duration = next_day*'24:00:00't + TT_member_arrived - Arrival_Time;
  minutes = duration / 60 ;
  format duration time10. minutes comma6.2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1683584388432.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83732i797F44840A67A33C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1683584388432.png" alt="Tom_0-1683584388432.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 22:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874569#M345549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-08T22:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874583#M345560</link>
      <description>&lt;P&gt;The only date that is available is the arrival date, however it's a separate variable. I assume I would need both the date/time for arrival_time and TT_member_arrived or would this would with just the start date/time?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 23:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874583#M345560</guid>
      <dc:creator>Shad</dc:creator>
      <dc:date>2023-05-08T23:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874584#M345561</link>
      <description>&lt;P&gt;Unfortunately, there is no better data source. I do have arrival date but it's a separate variable and there is no TT_member_arrived date available. But this work around is great. I think I got it working with a 12hour cut off.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 23:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874584#M345561</guid>
      <dc:creator>Shad</dc:creator>
      <dc:date>2023-05-08T23:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874596#M345573</link>
      <description>&lt;P&gt;Can you be a 100% sure that there will never, ever be a duration of more than 24 hours?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 04:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874596#M345573</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-09T04:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874712#M345617</link>
      <description>&lt;P&gt;For this instance, I think it's a safe assumption that there would not be an instance longer than 24 hours, yes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 17:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874712#M345617</guid>
      <dc:creator>Shad</dc:creator>
      <dc:date>2023-05-09T17:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating difference in minutes between two time stamps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874716#M345620</link>
      <description>&lt;P&gt;Ignoring the fact that you have missing data for arrival and TT Member arrival times, here's one approach&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have ;
	input ID $ Arrival_Time time. TT_member_arrived time.  ;
	format Arrival_Time time. TT_member_arrived time. ;
	if Arrival_Time&amp;lt;TT_member_arrived  then
		diffSecs=TT_member_arrived-Arrival_Time ;
	else 
		diffSecs="24:00"t-Arrival_Time+TT_member_arrived ;
	diffMins=diffSecs/60 ;

cards;
4077114 . 17:02:00
4077114 . 17:15:00
4077114 . 17:15:00
4077242 23:56:00 .
4077242 23:56:00 0:09:00
4077242 23:56:00 0:06:00
4077318 0:22:00 0:10:00
4077318 0:22:00 0:28:00
4077318 0:22:00 0:28:00
4077486 17:50:00 .
4077486 17:50:00 18:00:00
1776022 19:20:00 20:18:00
1776022 19:20:00 20:37:00
1776022 19:20:00 20:27:00
1776022 19:20:00 .
1776022 19:20:00 .
4078301 0:35:00 .
4078301 0:35:00 0:36:00
4078439 13:33:00 14:18:00
4078439 13:33:00 16:50:00
4078439 13:33:00 .
4078439 13:33:00 .
4078753 4:06:00 4:20:00
4078753 4:06:00 4:05:00
4078753 4:06:00 4:05:00
1813347 23:40:00 1:14:00
1813347 23:40:00 1:14:00
1813347 23:40:00 .
4079401 14:03:00 15:30:00
4079401 14:03:00 .
4079401 14:03:00 .
9980300 21:46:00 21:51:00
9980300 21:46:00 22:20:00
9980300 21:46:00 22:12:00
9980300 21:46:00 .
9980300 21:46:00 .
9980300 21:46:00 .
9980300 21:46:00 .
1975827 20:05:00 .
1975827 20:05:00 22:30:00
1975827 20:05:00 22:30:00
4079529 21:13:00 21:13:00
4079529 21:13:00 21:20:00
4079529 21:13:00 21:20:00
1828163 20:09:00 .
1828163 20:09:00 22:30:00
1828163 20:09:00 22:30:00
1828163 20:09:00 .
1676588 0:14:00 0:30:00
1676588 0:14:00 .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2023 17:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-difference-in-minutes-between-two-time-stamps/m-p/874716#M345620</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-05-09T17:39:45Z</dc:date>
    </item>
  </channel>
</rss>

