<?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: Time Accumulation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145320#M261939</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wile the retain method will meet your requirement, provided your data is sorted and you set duration to 0 at the start of a new group, I would suggest leaving that out in the data step and doing your summation in a subsequent SQL or Proc Means / Summary / Tabulate / Report (take your pick).&amp;nbsp; That gives you much more analytic flexibility - you can calculate the sum, the count, the max and min values of duration, and the median and mean etc.&amp;nbsp; It is also a more robust method as you are relying on a procedure to summarise thather than hand coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jun 2014 11:33:06 GMT</pubDate>
    <dc:creator>RichardinOz</dc:creator>
    <dc:date>2014-06-19T11:33:06Z</dc:date>
    <item>
      <title>Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145314#M261933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to total up some times and print them out to no avail. when I do a PUTLOG on TOTALTIME it says 0; I've tried doing a PUT with TIME5. and still no success. I am trying to RETAIN and sum up the DURATION time - any recommendations to accumate time for hours and minutes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RETAIN TOTALTIME;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATE_START=INPUT(BEGINDT, JULIAN7.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATE_END=INPUT(ENDDT, JULIAN7.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TIME_START=INPUT(BEGINTM, TIME10.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TIME_END=INPUT(ENDTM, TIME10.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DURATION=(DATE_END*86400+TIME_END) - (DATE_START*86400+TIME_START);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TOTALTIME =(TOTALTIME + DURATION);&lt;/P&gt;&lt;P&gt;PUTLOG 'TOTALTIME =' TOTALTIME;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2014 20:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145314#M261933</guid>
      <dc:creator>srosenfe</dc:creator>
      <dc:date>2014-06-17T20:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145315#M261934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Show some sample data.&lt;/P&gt;&lt;P&gt;Watch out for records with invalid values for one of your four input variables.&lt;/P&gt;&lt;P&gt;Try using SUM() function or SUM statement instead of simple addition so that missing values will be ignored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; xx;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;informat&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; dt1 dt2 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;datetime20.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; dt1 dt2 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;datetime20.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; duration totaltime &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;time.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; dt1 dt2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; duration = dt2 -dt1 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; totaltime+duration;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; (_n_ &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;_all_&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) (=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;01JAN2014:11:30 01JAN2014:11:45&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;01JAN2014:23:30 02JAN2014:01:45&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2014 21:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145315#M261934</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-06-17T21:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145316#M261935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like your data contains text representation of Julian dates.&amp;nbsp; I would suggest creating timestamps from your derived dates and times using the DHMS() function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Format TS_Start TS_End Datetime20. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TS_Start = DHMS(Date_Start, 0, 0, Time_Start) ;&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Duration = TS_End - TS_Start ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Duration in Seconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to address missing times using midnight as the default&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;TIME_START=SUM (0, INPUT(BEGINTM, TIME10.)) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 02:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145316#M261935</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2014-06-18T02:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145317#M261936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Some sample data is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATE_START =&lt;/P&gt;&lt;P&gt;14168&lt;/P&gt;&lt;P&gt;DATE_END =&lt;/P&gt;&lt;P&gt;14168&lt;/P&gt;&lt;P&gt;TIME_START=&lt;/P&gt;&lt;P&gt;23.30&lt;/P&gt;&lt;P&gt;TIME_END=&lt;/P&gt;&lt;P&gt;01.25&lt;/P&gt;&lt;P&gt;The DURATION is correct but I want to keep adding up the DURATION for a final HH.MM total&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 20:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145317#M261936</guid>
      <dc:creator>srosenfe</dc:creator>
      <dc:date>2014-06-18T20:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145318#M261937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;start='22Jan2014:08:14'dt;&lt;/P&gt;&lt;P&gt;end='22Jan2014:11:09'dt;&lt;/P&gt;&lt;P&gt;duration=end-start;&lt;/P&gt;&lt;P&gt;put duration=time5.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 00:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145318#M261937</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2014-06-19T00:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145319#M261938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the sum function instead of +, i.e. sum(total time, duration). If duration is correct, and your retain statement is included the total should be accumulating to the end of the data set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 03:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145319#M261938</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-06-19T03:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145320#M261939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wile the retain method will meet your requirement, provided your data is sorted and you set duration to 0 at the start of a new group, I would suggest leaving that out in the data step and doing your summation in a subsequent SQL or Proc Means / Summary / Tabulate / Report (take your pick).&amp;nbsp; That gives you much more analytic flexibility - you can calculate the sum, the count, the max and min values of duration, and the median and mean etc.&amp;nbsp; It is also a more robust method as you are relying on a procedure to summarise thather than hand coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 11:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145320#M261939</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2014-06-19T11:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145321#M261940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since, as you mentioned, the duration is correct, and the only thing lacking is the total time summed over observations, as Reeza mentioned, use the sum function. Here are the minor adjustments to you code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;retain totaltime 0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;date_start=input(begindt, julian7.);&lt;/P&gt;&lt;P&gt;date_end=input(enddt, julian7.);&lt;/P&gt;&lt;P&gt;time_start=input(begintm, time10.);&lt;/P&gt;&lt;P&gt;time_end=input(endtm, time10.);&lt;/P&gt;&lt;P&gt;duration=(date_end*86400+time_end) - (date_start*86400+time_start);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;totaltime = sum(totaltime, duration);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;putlog 'totaltime =' totaltime;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 22:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145321#M261940</guid>
      <dc:creator>WaltSmith</dc:creator>
      <dc:date>2014-06-19T22:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Time Accumulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145322#M261941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the great input - the RETAIN and SUM did just what I needed.&lt;/P&gt;&lt;P&gt;I then just did a PUT on it for time and it came out perfect with the following format:&lt;/P&gt;&lt;P&gt;TOTALTIMEO=PUT(TOTALTIME, TIME5.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again everybody for your recommendations -&lt;/P&gt;&lt;P&gt;Stephen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jun 2014 19:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-Accumulation/m-p/145322#M261941</guid>
      <dc:creator>srosenfe</dc:creator>
      <dc:date>2014-06-20T19:52:00Z</dc:date>
    </item>
  </channel>
</rss>

