<?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 Rows by Day in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396460#M95716</link>
    <description>Ha! Ofcourse! I just meant I didn't want to do a whole bunch of if 14&amp;lt;= day &amp;gt;1 then week = "week 1" sort of thing!!</description>
    <pubDate>Fri, 15 Sep 2017 19:31:03 GMT</pubDate>
    <dc:creator>daszlosek</dc:creator>
    <dc:date>2017-09-15T19:31:03Z</dc:date>
    <item>
      <title>Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396453#M95712</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find a way to sum the totals by day (data have, below) to the total by week (data want, below) without using the if/then statement (since I have over 200 days, this would take too long). I would like to find a more efficient way to do this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for your help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input day total;
datalines;
1 48
2 29
3 39
4 46
5 35
6 44
7 41
8 46
9 27
10 45
11 38
12 40
13 37
14 80
15 50
16 43
17 54
18 48
19 40
20 68
21 105
;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;total&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;Week 1&lt;/TD&gt;
&lt;TD align="right"&gt;282&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;Week 2&lt;/TD&gt;
&lt;TD align="right"&gt;313&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;Week 3&lt;/TD&gt;
&lt;TD align="right"&gt;408&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 19:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396453#M95712</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-09-15T19:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396457#M95714</link>
      <description>&lt;P&gt;Am i allowed to have one if then statement please? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 19:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396457#M95714</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-15T19:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396459#M95715</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52055"&gt;@daszlosek&lt;/a&gt;&amp;nbsp;Forgive me for 1 if then &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; have;&lt;/P&gt;&lt;P&gt;input day total;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 48&lt;/P&gt;&lt;P&gt;2 29&lt;/P&gt;&lt;P&gt;3 39&lt;/P&gt;&lt;P&gt;4 46&lt;/P&gt;&lt;P&gt;5 35&lt;/P&gt;&lt;P&gt;6 44&lt;/P&gt;&lt;P&gt;7 41&lt;/P&gt;&lt;P&gt;8 46&lt;/P&gt;&lt;P&gt;9 27&lt;/P&gt;&lt;P&gt;10 45&lt;/P&gt;&lt;P&gt;11 38&lt;/P&gt;&lt;P&gt;12 40&lt;/P&gt;&lt;P&gt;13 37&lt;/P&gt;&lt;P&gt;14 80&lt;/P&gt;&lt;P&gt;15 50&lt;/P&gt;&lt;P&gt;16 43&lt;/P&gt;&lt;P&gt;17 54&lt;/P&gt;&lt;P&gt;18 48&lt;/P&gt;&lt;P&gt;19 40&lt;/P&gt;&lt;P&gt;20 68&lt;/P&gt;&lt;P&gt;21 105&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;do until(last);&lt;/P&gt;&lt;P&gt;Week_total=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;Week+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;do _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; by &lt;STRONG&gt;1&lt;/STRONG&gt; until(_n_=&lt;STRONG&gt;7&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;set have end=last;&lt;/P&gt;&lt;P&gt;Week_total+total;&lt;/P&gt;&lt;P&gt;if _n_=&lt;STRONG&gt;7&lt;/STRONG&gt; then output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;keep Week:;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 19:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396459#M95715</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-15T19:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396460#M95716</link>
      <description>Ha! Ofcourse! I just meant I didn't want to do a whole bunch of if 14&amp;lt;= day &amp;gt;1 then week = "week 1" sort of thing!!</description>
      <pubDate>Fri, 15 Sep 2017 19:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396460#M95716</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-09-15T19:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396461#M95717</link>
      <description>&lt;P&gt;LoL Thank you and have a nice day. Cheers!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 19:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396461#M95717</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-15T19:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396463#M95719</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(where= (wf =0) keep=day c_total wf);
set have;
wf = mod(day,7);
flag = wf ~=1;
retain c_total 0;
c_total = (c_total*flag + total);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 19:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396463#M95719</guid>
      <dc:creator>sk423</dc:creator>
      <dc:date>2017-09-15T19:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396465#M95720</link>
      <description>&lt;P&gt;Proc SQL approach:&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_sql as
select ceil(day/7) as week, sum(total) as w_total
from have
group by calculated week
order by week
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 20:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396465#M95720</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-09-15T20:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Summing Rows by Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396483#M95729</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52055"&gt;@daszlosek&lt;/a&gt;&amp;nbsp;my apologies, I should have tested to avoid the IF THEN:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;Week_total=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;Week+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;do _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; by &lt;STRONG&gt;1&lt;/STRONG&gt; until(_n_=&lt;STRONG&gt;7&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;Week_total+total;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;keep Week:;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 20:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-Rows-by-Day/m-p/396483#M95729</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-15T20:44:18Z</dc:date>
    </item>
  </channel>
</rss>

