<?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: Summing event times in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687541#M208729</link>
    <description>&lt;P&gt;Your query is nothing more than&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE want AS SELECT
  *,stop-start as totaldays
  FROM have;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 15:10:54 GMT</pubDate>
    <dc:creator>CurtisMackWSIPP</dc:creator>
    <dc:date>2020-09-29T15:10:54Z</dc:date>
    <item>
      <title>Summing event times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687535#M208724</link>
      <description>&lt;P&gt;I need to sum some total event times.&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Event&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Start&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Stop&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;a&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;b&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;8&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;c&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;16&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;
&lt;P&gt;20&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if I wanted to sum the total time an event was occurring it would be days 1-12 and 16-20 as I want to not double count overlapping dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now this could be done simply with the following code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA part1;
  SET have;
  DO day=start to stop;
    OUTPUT;
   END;
RUN;
PROC SQL;
  CREATE TABLE want AS SELECT
  distinct(count(distinct(day)) as totaldays
  FROM part1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However once we get to many events and many subjects the dataset in part1 can become very very large.&amp;nbsp; Is there a more elegant solution I am missing?&lt;/P&gt;
&lt;P&gt;* There may be syntax errors in the code above, I am not bothered about that, it is just my typing out loud without running it.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687535#M208724</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2020-09-29T14:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Summing event times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687541#M208729</link>
      <description>&lt;P&gt;Your query is nothing more than&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE want AS SELECT
  *,stop-start as totaldays
  FROM have;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687541#M208729</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-29T15:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summing event times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687729#M208818</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339357"&gt;@CurtisMackWSIPP&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry no this would not work,I was not clear enough.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the sum of total days . In this case 17. (days 1,2,3,4,5,6,7,8,9,10,11,12,16,17,18,19,20).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So as a better example&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;Grp&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Event&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Start&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Stop&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;X&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;a&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;X&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;b&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;8&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;X&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;c&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;16&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;X&lt;/TD&gt;
&lt;TD&gt;d&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;Y&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;e&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cleaning up the code some.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA part1;
  SET have;
  DO day=start to stop;
    OUTPUT;
   END;
RUN;
PROC SQL;
  CREATE TABLE want AS SELECT
  distinct grp, count(distinct(day)) as totaldays
  FROM part1
  GROUP BY grp;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;Grp&lt;/TD&gt;
&lt;TD width="50%"&gt;totaldays&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;X&lt;/TD&gt;
&lt;TD width="50%"&gt;17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;Y&lt;/TD&gt;
&lt;TD width="50%"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 06:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687729#M208818</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2020-09-30T06:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Summing event times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687835#M208861</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=",";
input Grp $	Event $	Start	Stop;
datalines;
X,a,1,10
X,b,8,12
X,c,16,20
X,d,1,10
Y,e,3,4
;
run;
 
DATA want(keep = grp totaldays);
  SET have;
  by grp;
  array days [1:100] _temporary_;
  DO day=start to stop;
    days(day) = 1;
  END;
  if last.grp then do;
    totaldays = sum(of days(*));
    output;
    call missing(of days(*));
  end;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 14:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/687835#M208861</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-30T14:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Summing event times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/688193#M209018</link>
      <description>I like it! Using an array that way had never crossed my mind.  Thank you.</description>
      <pubDate>Thu, 01 Oct 2020 13:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-event-times/m-p/688193#M209018</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2020-10-01T13:36:56Z</dc:date>
    </item>
  </channel>
</rss>

