<?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: computing sum and average by every nth row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348597#M80738</link>
    <description>&lt;P&gt;If your sample data looks "&lt;STRONG&gt;exactly like"&lt;/STRONG&gt; what you presented, here is one easy way:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;sum+amount;&lt;BR /&gt;count+1;&lt;BR /&gt;if mod(period,3)=0 then do;&lt;BR /&gt;average=divide(sum,count);&lt;BR /&gt;output;&lt;BR /&gt;sum=0;&lt;BR /&gt;average=0;&lt;BR /&gt;count=0;&lt;BR /&gt;end;&lt;BR /&gt;drop count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Apr 2017 06:10:42 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2017-04-10T06:10:42Z</dc:date>
    <item>
      <title>computing sum and average by every nth row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348587#M80731</link>
      <description>&lt;P&gt;Hi, I would like to compute sum ( bal_rev = R ) and average (bal_rev = B) by every 3 period for each state. &amp;nbsp;Could you please help ? Thanks !&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
input State $ Period Bal_Rev $ AMOUNT;
datalines;
CA 1 B 1464.48
CA 2 B 1275.81
CA 3 B 943.28
CA 4 B 849.82
CA 5 B 752.29
CA 6 B 661.56
CA 1 R 4.86
CA 2 R 4.86
CA 3 R 4.3
CA 4 R 3.57
CA 5 R 3.19
CA 6 R 2.97
NV 1 B 1047.84
NV 2 B 1045.54
NV 3 B 1092.74
NV 4 B 1110.41
NV 5 B 1134.34
NV 6 B 1105.86
NV 1 R 4.91
NV 2 R 6.09
NV 3 R 6.8
NV 4 R 5.84
NV 5 R 7.22
NV 6 R 10.16
UT 1 B 9856.37
UT 2 B 9825.48
UT 3 B 9701.09
UT 4 B 9497.63
UT 5 B 9448.09
UT 6 B 9293.51
UT 1 R 13.09
UT 2 R 12.7
UT 3 R 11.35
UT 4 R 8.14
UT 5 R 16.72
UT 6 R 16.19
;
run;

data want;;
set have;
if bal_rev ='B' then do;
/* average value for every 3 period for each state */
end;
if bal_rev = 'R' then do;
/* sum value for every 3 period for each state */
end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 04:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348587#M80731</guid>
      <dc:creator>octrout</dc:creator>
      <dc:date>2017-04-10T04:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: computing sum and average by every nth row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348590#M80734</link>
      <description>proc sql;&lt;BR /&gt;select state,qtr,bal_rev,avg(amount) as Avg_amount,sum(amount) as sum_amount from&lt;BR /&gt;(select *,&lt;BR /&gt;case when period in (1,2,3) then 'qtr1'&lt;BR /&gt;when period in (4,5,6) then 'qtr2'&lt;BR /&gt;end as qtr from have)&lt;BR /&gt;group by bal_rev,state,qtr;&lt;BR /&gt;quit;</description>
      <pubDate>Mon, 10 Apr 2017 05:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348590#M80734</guid>
      <dc:creator>lakshmi_74</dc:creator>
      <dc:date>2017-04-10T05:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: computing sum and average by every nth row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348597#M80738</link>
      <description>&lt;P&gt;If your sample data looks "&lt;STRONG&gt;exactly like"&lt;/STRONG&gt; what you presented, here is one easy way:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;sum+amount;&lt;BR /&gt;count+1;&lt;BR /&gt;if mod(period,3)=0 then do;&lt;BR /&gt;average=divide(sum,count);&lt;BR /&gt;output;&lt;BR /&gt;sum=0;&lt;BR /&gt;average=0;&lt;BR /&gt;count=0;&lt;BR /&gt;end;&lt;BR /&gt;drop count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 06:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-sum-and-average-by-every-nth-row/m-p/348597#M80738</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-10T06:10:42Z</dc:date>
    </item>
  </channel>
</rss>

