<?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: Correcting negative time intervals in SAS code in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712857#M27084</link>
    <description>&lt;P&gt;It is safe to assume that the time point in time2 is later than the point in time1, right?&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2021 19:33:43 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-01-20T19:33:43Z</dc:date>
    <item>
      <title>Correcting negative time intervals in SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712854#M27082</link>
      <description>&lt;P&gt;In my code I am attempting to calculate the elapsed time between two time points (response time). I have formatted all of my time variables into the "time." format in SAS. In majority of cases, I am able to calculate a positive elapsed time by subtracting time point 2 from time point 1 (i.e. 19:24:01 - 19:19:22 = 0:04:39 = 4 minutes 39 seconds elapsed).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although there is a select group of observations where the time window crossed 12am (i.e.&amp;lt;23:59:59&amp;nbsp; and &amp;gt;00:00:00). Using my method to calculate the elapsed time, I am getting negative elapsed time. For example the time interval between 11:58:35PM and 0:05:51AM is calculated as -23:52, when the true interval should be 0:07:16 (7 minutes 16 seconds).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know of a simple way to correct these observations? See current simple SAS code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datawithtime;
set rawdata;
elapsedtime=time2-time1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 19:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712854#M27082</guid>
      <dc:creator>njgrubic</dc:creator>
      <dc:date>2021-01-20T19:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Correcting negative time intervals in SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712856#M27083</link>
      <description>Do you have the dates somewhere? If you can add the date component in, that's the best fix. Otherwise, could you also have times that are well over 24 hours which may also cross dates and you wouldn't know?&lt;BR /&gt;&lt;BR /&gt;For negatives you could just add dates but I wouldn't trust that to catch all cases, so it depends on your situation.</description>
      <pubDate>Wed, 20 Jan 2021 19:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712856#M27083</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-20T19:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Correcting negative time intervals in SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712857#M27084</link>
      <description>&lt;P&gt;It is safe to assume that the time point in time2 is later than the point in time1, right?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 19:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712857#M27084</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-20T19:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Correcting negative time intervals in SAS code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712862#M27085</link>
      <description>&lt;P&gt;If so, just add the number of seconds in a day (86400) to the result if it is negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (time1 time2)(:hhmmss8.);
format time: timeampm.;
datalines;
23:58:35 00:05:51AM
;

data want;
   set have;
   elapsedtime = ifn(time2 &amp;lt; time1, time2 - time1 + 86400, time2 - time1);
   format elapsedtime time.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;time1        time2        elapsedtime 
11:58:35 PM  12:05:51 AM  0:07:16 &lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 19:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Correcting-negative-time-intervals-in-SAS-code/m-p/712862#M27085</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-20T19:46:56Z</dc:date>
    </item>
  </channel>
</rss>

