<?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: cumul duration time by range time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cumul-duration-time-by-range-time/m-p/774858#M246305</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data modify;
    set have;
    /* Determine if start to end time crosses 30 minute boundary */
    start_period=round(tsp_start-900,1800);
    end_period=round(tsp_end-900,1800);
    /* If start_period &amp;lt; end_period then we need to split the row into two or more rows */
    if start_period &amp;lt; end_period then do;
        delta=floor(end_period-start_period)/1800;
        do i=0 to delta;
            duration=(min(end_period,tsp_end)-tsp_start);
            output;
            start_period=start_period+1800;
            tsp_start=end_period;
            end_period=end_period+1800;
        end; 
    end;
    else do;
        duration=tsp_end-tsp_start;
        output;
    end;
    format start_period end_period datetime18. duration time.;
    drop i;
run;
proc summary data=modify nway;
    class start_period status;
    var duration;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Oct 2021 11:26:04 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-10-18T11:26:04Z</dc:date>
    <item>
      <title>cumul duration time by range time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumul-duration-time-by-range-time/m-p/774843#M246301</link>
      <description>&lt;PRE&gt;data have;
input employee $ tsp_start tsp_end datetime18. status $ ;
informat tsp_start tsp_end datetime18.;
format tsp_start tsp_end datetime18. ;
format employee status $4. ;
datalines ;
AAAA 10SEP2121:08:00:00 10SEP2121:08:04:00 BUSY
AAAA 10SEP2121:08:05:30 10SEP2121:08:12:30 CALL
AAAA 10SEP2121:08:14:20 10SEP2121:08:15:20 BUSY
AAAA 10SEP2121:08:28:20 10SEP2121:08:34:20 CALL
AAAA 10SEP2121:08:35:00 10SEP2121:08:40:10 BUSY
;
run;


data want;
input employee $ range_below range_top datetime18. status $ duration time. ;
informat range_below range_top datetime18.;
format range_below range_top datetime18. ;
format employee status $4. ;
format duration time. ;
datalines ;
AAAA 10SEP2121:08:00:00 10SEP2121:08:30:00 BUSY 00:05:00
AAAA 10SEP2121:08:00:00 10SEP2121:08:30:00 CALL 00:08:40
AAAA 10SEP2121:08:30:00 10SEP2121:09:00:00 BUSY 00:05:10
AAAA 10SEP2121:08:30:00 10SEP2121:09:09:00 CALL 00:04:20
;
run;
&lt;/PRE&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;some emlpoyees make calls. calls have begin time and end time so duration.&lt;/P&gt;
&lt;P&gt;there are "call" phases and "busy" phases.&lt;/P&gt;
&lt;P&gt;I would like to calculate duraiton time of "call" phase and "busy" phase but for every range time. a range is 30min duration. so&lt;/P&gt;
&lt;P&gt;range1 is from 08:00 to 08:30&lt;/P&gt;
&lt;P&gt;range2 is from 08:30 to 09:00&lt;/P&gt;
&lt;P&gt;range3 is from 09:00 to 09:30&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;range 24 from 19:30 to 20:00&lt;/P&gt;
&lt;P&gt;for example, in the "want" table, row 2 the duration is 08:40 (concerning range 08:00 to 08:30) because we cumulate 7 min (08:05:30 to 08:12:30) and 1:30 (coming from row 5, 08:28:20 to 08:30:00)&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;P&gt;kind regards&lt;/P&gt;
&lt;P&gt;Nass&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 09:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumul-duration-time-by-range-time/m-p/774843#M246301</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-10-18T09:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: cumul duration time by range time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumul-duration-time-by-range-time/m-p/774858#M246305</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data modify;
    set have;
    /* Determine if start to end time crosses 30 minute boundary */
    start_period=round(tsp_start-900,1800);
    end_period=round(tsp_end-900,1800);
    /* If start_period &amp;lt; end_period then we need to split the row into two or more rows */
    if start_period &amp;lt; end_period then do;
        delta=floor(end_period-start_period)/1800;
        do i=0 to delta;
            duration=(min(end_period,tsp_end)-tsp_start);
            output;
            start_period=start_period+1800;
            tsp_start=end_period;
            end_period=end_period+1800;
        end; 
    end;
    else do;
        duration=tsp_end-tsp_start;
        output;
    end;
    format start_period end_period datetime18. duration time.;
    drop i;
run;
proc summary data=modify nway;
    class start_period status;
    var duration;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 11:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumul-duration-time-by-range-time/m-p/774858#M246305</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-18T11:26:04Z</dc:date>
    </item>
  </channel>
</rss>

