<?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: How to calculate difference time (minutes) between two rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414554#M101579</link>
    <description>&lt;P&gt;This is a good situation for the DIF function embedded in an IFN function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by day;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; difference=ifn(first.day,.,dif(hour));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; format difference time8.0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2017 22:15:16 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-11-17T22:15:16Z</dc:date>
    <item>
      <title>How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414517#M101560</link>
      <description>&lt;P&gt;I'm a layman in SAS. I'm using SAS Enterprise Guide and I have a problem.&lt;/P&gt;&lt;P&gt;I need to calculate the difference time (minutes) between two rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, only calculate the difference when it's on the same day.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="swws.JPG" style="width: 206px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16716iDA7AA098B150CC24/image-size/large?v=v2&amp;amp;px=999" role="button" title="swws.JPG" alt="swws.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How to calculate difference time and to create the Difference Column?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 19:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414517#M101560</guid>
      <dc:creator>guimeleiro</dc:creator>
      <dc:date>2017-11-17T19:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414524#M101563</link>
      <description>&lt;P&gt;Is your hour variable an actual SAS date value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And do you want the result to be a count of minutes? Your result shows a time value but I am going to guess that's because you're working in Excel.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 20:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414524#M101563</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-17T20:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414533#M101566</link>
      <description>&lt;P&gt;I imported the Excel data.&lt;BR /&gt;Actually "day" and "hour" are SAS date value.&lt;/P&gt;&lt;P&gt;Yes, I want&amp;nbsp;&lt;SPAN&gt;the result to be a count of minutes.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 20:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414533#M101566</guid>
      <dc:creator>guimeleiro</dc:creator>
      <dc:date>2017-11-17T20:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414550#M101575</link>
      <description>&lt;P&gt;This will give you the number of minutes with a&amp;nbsp;caveat.&lt;/P&gt;
&lt;P&gt;If your hour variable actually have second components you may not get what you want because the intck function counts interval boundaries. The second code example shows the time values 2 seconds apart but the function returns 1 "minute" interval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;If you need 60-second minutes then you'll get into some different rounding such as round( (hour-lhour)/60, 1) or possibly Floor or Ceil instead of Round depending on your need.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by day;
   lhour=lag(hour);
   if first.day then difference=.;
   else difference = intck('minute',lhour,hour);
   drop lhour;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data junk;
   x= "12:10:59"t;
   y= "12:11:01"t;
   interval = intck('minute',x,y);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 22:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414550#M101575</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-17T22:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414554#M101579</link>
      <description>&lt;P&gt;This is a good situation for the DIF function embedded in an IFN function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by day;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; difference=ifn(first.day,.,dif(hour));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; format difference time8.0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 22:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/414554#M101579</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-11-17T22:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/415311#M101832</link>
      <description>Other doubt:&lt;BR /&gt;In case I want to calculate difference time (minutes) between two rows by conditioning it for day and group (Group A or Group B, for example), I put:&lt;BR /&gt;&lt;BR /&gt;if first.day and first.group then difference=.;&lt;BR /&gt;&lt;BR /&gt;Or Is there another way?&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Nov 2017 20:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/415311#M101832</guid>
      <dc:creator>guimeleiro</dc:creator>
      <dc:date>2017-11-21T20:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/487784#M127115</link>
      <description>&lt;P&gt;How could I do the same process but have the last observation per group be the missing value. Such that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture.PNG" style="width: 243px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22538i1F9C43B4B6345EAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: It looks as if I could use this methodology - &lt;A href="http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back" target="_blank"&gt;http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 14:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/487784#M127115</guid>
      <dc:creator>MB_Analyst</dc:creator>
      <dc:date>2018-08-17T14:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference time (minutes) between two rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/487970#M127165</link>
      <description>&lt;P&gt;Yes, you can use that methodology:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=next_hour);
  set have end=end_of_have;
  by day;
  set have (firstobs=2 keep=hour rename=(hour=next_hour));
  if last.day=0 then time_to_next=next_hour-hour;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Aug 2018 00:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-difference-time-minutes-between-two-rows/m-p/487970#M127165</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-08-18T00:23:28Z</dc:date>
    </item>
  </channel>
</rss>

