<?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: grouping by 10 min time windows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498004#M132201</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Merci&amp;nbsp; (Thank you very much= Merci Beaucoup) &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Sep 2018 23:35:40 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-21T23:35:40Z</dc:date>
    <item>
      <title>grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497855#M132117</link>
      <description>&lt;P&gt;I have a table that looks like this&lt;/P&gt;&lt;P&gt;Time&amp;nbsp; Books&lt;/P&gt;&lt;P&gt;16:01&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;16:02&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;16:03&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;16:09&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;16:11&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;16:12&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;16:55&amp;nbsp; 8&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to group by 10 min time windows so that I get a table that looks like this&lt;/P&gt;&lt;P&gt;Time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Avg(Books)&lt;/P&gt;&lt;P&gt;16:01 - 16:10&amp;nbsp;&amp;nbsp; 3.75&lt;/P&gt;&lt;P&gt;16:11 - 16:20&amp;nbsp;&amp;nbsp; 3.5&lt;/P&gt;&lt;P&gt;16:51 - 17:00&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 15:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497855#M132117</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-21T15:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497879#M132133</link>
      <description>&lt;P&gt;Do you have continuous data for the 10 minute windows for your entire dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;meaning 11-20,21-20 and so on unlike a break after16:12 --16:55&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 15:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497879#M132133</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-21T15:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497880#M132134</link>
      <description>&lt;P&gt;There are breaks like the one you pointed out.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 15:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497880#M132134</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-21T15:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497884#M132137</link>
      <description>&lt;P&gt;Ok I do have solution in my mind but let me wait for somebody to give a robust solution who does well in times series. I suppose they may even suggest you SAS ETS procs like proc expand and proc timeseries or even a nice datastep solution. hang in there.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 15:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497884#M132137</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-21T15:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497885#M132138</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me with this?&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Creating-TimeStamp-with-Hour-and-Minute-Values/m-p/497883#M132136" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Creating-TimeStamp-with-Hour-and-Minute-Values/m-p/497883#M132136&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 15:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497885#M132138</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-21T15:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497892#M132142</link>
      <description>&lt;P&gt;You will need to convert times to&amp;nbsp; SAS values using the HMS(hour, minute, second) function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;Create user-defined format $time :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC FORMAT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; VALUE time;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HMS(16, 1, 0) - HMS(16, 10, 0) = "16:01 - 16:10"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HMS(16, 11, 0) - HMS(16, 20, 0) = "16:11 - 16:20"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HMS(16, 51, 0)&amp;nbsp; - HMS(17, 0, 0) = "16:51 - 17:00" ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Group by formatted values using PROC SQL (&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-Group-By-Formatted-Values/td-p/187278" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-Group-By-Formatted-Values/td-p/187278&lt;/A&gt;) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;SELECT put(Time, $time.) AS Time, avg(Books)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;FROM dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;GROUP BY time;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 16:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497892#M132142</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2018-09-21T16:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497911#M132154</link>
      <description>&lt;P&gt;The HMS function does not work inside of PROC FORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems to me that the solution to the original problem may require some macro coding and looping to create the formats properly (or alternatively CALL EXECUTE could do this as well). I cannot think of a way to create the formats without some sort of macro or CALL EXECUTE. Once the format is created properly, then PROC SUMMARY will give you the results very easily.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 17:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497911#M132154</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-21T17:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497913#M132156</link>
      <description>&lt;P&gt;Wait! I just thought of a way to do this without macros or CALL EXECUTE. You could use the CNTLIN= option in PROC FORMAT, but I don't really have the time to work out the code right now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always forget about the CNTLIN= option. I hate it when that happens.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 17:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497913#M132156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-21T17:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497923#M132161</link>
      <description>&lt;P&gt;Combining all the good suggestions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input time :time. books;
format time time5.;
cards;
16:01 3
16:02 5
16:03 4
16:09 3
16:11 2
16:12 5
16:55 8
;

data tfmt / view=tfmt;
fmtname='timewin';
do start='0:01't to '23:51't by '0:10't;
  end=start+'0:10't;
  eexcl='Y';
  label=put(start,time5.)||' - '||put(end-1,time5.);
  output;
end;
proc format cntlin=tfmt;
run;

proc sql;
create table want as
select put(time, timewin.) as timewin label='Time',
       avg(books) as avg_books label='Avg(Books)'
from have
group by timewin;
quit;

proc print data=want label;
format avg_books 10.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Edit: Extended the ranges of the format to avoid gaps between them.&lt;/P&gt;
&lt;P&gt;Edit 2: Restored code highlighting and indentation [bug in forum software?])&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 20:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497923#M132161</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-21T20:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497927#M132163</link>
      <description>&lt;P&gt;INTNX&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data time;
   input Time:time.  Books;
   g1 = intnx('MINUTE10.2',time,0,'B');
   g2 = intnx('MINUTE10.2',time,0,'E');
   format time g: time5.;
   cards;
16:01  3
16:02  5
16:03  4
16:09  3
16:11  2
16:12  5
16:55  8
;;;;
   run;
proc print;
   run;
proc summary nway;
   class g:;
   output out=avg10 mean(books)=avgbooks;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 302px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23451i02CA37DDCDE7AB04/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 17:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497927#M132163</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-09-21T17:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497929#M132165</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;Brilliance personified. I never really properly understood the computation of intervals like&lt;EM&gt;&lt;STRONG&gt; interval.x&lt;/STRONG&gt;&lt;/EM&gt; MINUTE10.2 although I have readthe doc a few times.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 17:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497929#M132165</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-21T17:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497934#M132167</link>
      <description>Brilliance no.  More like trial and error.</description>
      <pubDate>Fri, 21 Sep 2018 18:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497934#M132167</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-09-21T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497986#M132192</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&amp;nbsp;or even a nice datastep solution. (...)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep=timewin avg_books rename=(timewin=Time));
do n=1 by 1 until(eof | time&amp;gt;=w+600);
  set have end=eof;
  w=round(time-360,600)+60;
  timewin=put(w,time5.)||' - '||put(w+540,time5.);
  s=sum(s,books);
  if ~eof then set have(firstobs=2 keep=time);
end;
Avg_Books=s/n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure if it's "nice", but it's a datastep solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Edit:&amp;nbsp;Minor simplification: Variable TIME in the second SET statement doesn't need to be renamed. Its value is used in the UNTIL condition.)&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 22:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497986#M132192</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-21T22:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497987#M132193</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; &lt;U&gt;Marvelous and yet another &lt;STRONG&gt;golf&lt;/STRONG&gt; feather&lt;/U&gt;. It took me&amp;nbsp; a&amp;nbsp; while to understand the genie in that code and certainly not the novice/mid level. So to be fair, and not knowing OP's level and for the benefit of wider audience,may i request you to add a couple of notes if you don't mind at your own convenience plz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you &amp;amp; Can't appreciate enough&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 21:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497987#M132193</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-21T21:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497991#M132196</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Brilliance no. More like trial and error.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And I suspect a certain amount of persistence.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 21:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/497991#M132196</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-21T21:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498002#M132199</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The process is as follows:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Variable N is set to 1.&lt;/LI&gt;
&lt;LI&gt;The first SET statement reads the first or (in subsequent iterations of the data step) the &lt;EM&gt;next&lt;/EM&gt; observation from dataset HAVE.&lt;/LI&gt;
&lt;LI&gt;Determine the time window of the TIME value just read. W is the lower limit of that interval. Example: TIME='16:03't, this minus 6 minutes (360 s) is '15:57't, rounded to 10 minutes is '16:00't, plus 60 s gives '16:01't.&lt;/LI&gt;
&lt;LI&gt;Construct the display value of the time window. (Upper limit is lower limit plus 9*60 s.)&lt;/LI&gt;
&lt;LI&gt;Add current value of BOOKS to variable S. The SUM function has two nice properties: It treats missing values of S (e.g. in the very first call) as zeros (unlike &lt;FONT face="courier new,courier"&gt;s=s+books;&lt;/FONT&gt;) and it doesn't imply a RETAIN (as the sum &lt;EM&gt;statement&lt;/EM&gt;, &lt;FONT face="courier new,courier"&gt;s+books;&lt;/FONT&gt;, would).&lt;/LI&gt;
&lt;LI&gt;If the last observation of HAVE hasn't been reached yet (end-of-file variable EOF=0, hence condition "not EOF" is true), look ahead into the next observation of HAVE and retrieve its TIME value.* Thanks to the FIRSTOBS=2 option the second SET statement is always "one observation ahead". The KEEP= option has only performance reasons here. It's not mandatory.&lt;/LI&gt;
&lt;LI&gt;At the bottom of the DO-UNTIL loop the UNTIL condition is checked: If the very last observation (EOF=1) or the last observation of the current time window (criterion: the TIME value of the next obs. belongs to a later time window, i.e. is greater than or equal to the left endpoint of the current window plus 10 min) has been reached, the loop terminates and the accumulated number of books, S, is divided by the corresponding number of observations, N (which had been incremented "&lt;FONT face="courier new,courier"&gt;by 1&lt;/FONT&gt;" in each iteration of the loop). The result is stored in variable Avg_Books and written to dataset WANT by the implied OUTPUT statement of the data step, together with variable TIMEWIN, renamed to Time for "cosmetic" reasons. Else, if the UNTIL condition is &lt;EM&gt;not&lt;/EM&gt; met, we continue at step 2 above with N incremented by 1.&lt;/LI&gt;
&lt;LI&gt;At the beginning of the next iteration of the data step, i.e., immediately before we start over at step 1 above, variable S (and all other non-retained variables) is automatically set to missing, as usual. Thus, none of the cumulative values is carried over from one time window to the next. If the last observation of HAVE&amp;nbsp;was reached in the previous iteration, the data step is terminated as soon as the first SET statement is executed again. Without the IF condition "&lt;FONT face="courier new,courier"&gt;~eof&lt;/FONT&gt;" the &lt;EM&gt;second&lt;/EM&gt; SET statement would terminate the datastep prematurely because it's "one observation ahead".&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*I realize now that we may overwrite TIME, i.e., renaming was unnecessary (have updated the code).&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 23:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498002#M132199</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-21T23:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498003#M132200</link>
      <description>&lt;P&gt;for what it's worth, my fun part&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Time :time5.  Books;
format time time5.;
cards;
16:01  3
16:02  5
16:03  4
16:09  3
16:11  2
16:12  5
16:55  8
;

data temp;
do time=60 to 86400 by 60 ;
if mod(minute(time),10)=1 then grp+1;
output;
end;
format time time5.;
run;

proc sql;
create table want as
select   catx('-',put(min(a.time),time5.),put(max(a.time),time5.)) as time,mean(books) as avg 
from temp a left join have b
on a.time=b.time
group by grp
having avg ne .
order by grp,time;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Sep 2018 23:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498003#M132200</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-21T23:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498004#M132201</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Merci&amp;nbsp; (Thank you very much= Merci Beaucoup) &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 23:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498004#M132201</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-21T23:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498062#M132243</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Time : time5. Books;
format time hhmm5.;
cards;
16:01  3
16:02  5
16:03  4
16:09  3
16:11  2
16:12  5
16:55  8
;
run;

data temp;
 set have;
 retain temp;
 if _n_=1 then temp=time;
 if time&amp;gt;temp+'00:09:00't then do;group+1;temp=time;end;
 drop temp;
run;

proc sql;
create table want as
 select catx(' - ',put(min(time),hhmm5.),put(min(time)+'00:09:00't,hhmm5.)) as time,
 mean(books) as avg_books
  from temp
   group by group;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Sep 2018 11:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/498062#M132243</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-22T11:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: grouping by 10 min time windows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/499753#M133020</link>
      <description>&lt;P&gt;Make it even "nicer" with time literals:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep=timewin avg_books rename=(timewin=Time));
do n=1 by 1 until(eof or time &amp;gt;= w + '00:10:00't);
  set have end=eof;
  w=round(time - '00:06:00't, '00:10:00't) + '00:01:00't;
  timewin=put(w, time5.)||' - '||put(w + '00:09:00't, time5.);
  s=sum(s, books);
  if not eof then set have(firstobs=2 keep=time);
end;
Avg_Books=s/n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 02:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/grouping-by-10-min-time-windows/m-p/499753#M133020</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-28T02:06:14Z</dc:date>
    </item>
  </channel>
</rss>

