<?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: Summary of top 3 values by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538381#M148207</link>
    <description>&lt;P&gt;Are you after this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input memberid : $	industry	amount;
cards;
A2348	110	10045643
A5469	110	9543376
A21563	110	9034166
D6765	110	4876
B2345	110	46
A5463	111	89
A9876	111	30
B8766	112	583497
A5689	112	525488
D9655	112	75158
A4566	112	43866
D67896	112	1865
D4566	112	568
A2876	112	366
;

data want;
if 0 then set have;
sum=0;
do _n_=1 by 1 until(last.industry);
set have;
by industry;
sum+(_n_&amp;lt;=3)*amount;
end;
drop amount;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Feb 2019 19:07:39 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-02-25T19:07:39Z</dc:date>
    <item>
      <title>Summary of top 3 values by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538378#M148204</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A seemingly easy task of summarizing a variable by group has become challenging when I was asked to find the sum of only top three values in each group. I attached a sample table here. Need to find the totals of top 3 amounts for each industry group (amounts are already sorted in descending order). Some industry groups have only one or two records. Can anybody help me with this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 18:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538378#M148204</guid>
      <dc:creator>DiG</dc:creator>
      <dc:date>2019-02-25T18:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of top 3 values by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538381#M148207</link>
      <description>&lt;P&gt;Are you after this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input memberid : $	industry	amount;
cards;
A2348	110	10045643
A5469	110	9543376
A21563	110	9034166
D6765	110	4876
B2345	110	46
A5463	111	89
A9876	111	30
B8766	112	583497
A5689	112	525488
D9655	112	75158
A4566	112	43866
D67896	112	1865
D4566	112	568
A2876	112	366
;

data want;
if 0 then set have;
sum=0;
do _n_=1 by 1 until(last.industry);
set have;
by industry;
sum+(_n_&amp;lt;=3)*amount;
end;
drop amount;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 19:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538381#M148207</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-25T19:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of top 3 values by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538385#M148210</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4655"&gt;@DiG&lt;/a&gt;&amp;nbsp; if the previous is not clear. the traditional method as follows&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by industry;
if first.industry then do; n=1;sum=0;end;
else n+1;
sum+(n&amp;lt;=3)*amount;
if last.industry;
drop n amount;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Feb 2019 19:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538385#M148210</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-25T19:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of top 3 values by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538397#M148216</link>
      <description>&lt;P&gt;It works!&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_8" style="color: #009999;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205" target="_self"&gt;&lt;SPAN class="login-bold"&gt;novinosrin&lt;/SPAN&gt;&lt;/A&gt; !&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 19:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summary-of-top-3-values-by-group/m-p/538397#M148216</guid>
      <dc:creator>DiG</dc:creator>
      <dc:date>2019-02-25T19:29:38Z</dc:date>
    </item>
  </channel>
</rss>

