<?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: Top Values based on other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501255#M133632</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Field $	field_value &amp;amp; $	cnt_val;
cards;
AB123	Note 1	100
AB123	Note 2	90
AB123	Note 3	46
AB123	Note 4	23
AB123	Note 5	12
AB123	Note 6	10
AB123	Note 7	5
BC234	Note 1	1065
BC234	Note 2	456
BC234	Note 3	231
BC234	Note 4	153
BC234	Note 5	100
BC234	Note 6	56
;

proc rank data=have out=want(where=(cnt_val_rank&amp;lt;=3)) ties=low descending;
   by field notsorted;
   var cnt_val ;
   ranks cnt_val_rank ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Oct 2018 19:06:17 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-10-03T19:06:17Z</dc:date>
    <item>
      <title>Top Values based on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501251#M133628</link>
      <description>&lt;P&gt;good Day,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I currently have a SAS create table proc where I do count of how many times a certain value occurs based on another value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example in the data below there is a count for how many times the field value occured within the field.&amp;nbsp; For field AB123 the value Note 1 appeared 100 times in teh database and etc.&amp;nbsp; I want to pull the top 3 values for each field.&amp;nbsp; Based on the table below for AB123 i should get the data for the values of Note 1, Note 2 and Note 3.&amp;nbsp; I hope this makes sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="336"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="112"&gt;Field&lt;/TD&gt;
&lt;TD width="112"&gt;field_value&lt;/TD&gt;
&lt;TD width="112"&gt;cnt_val&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 1&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 2&lt;/TD&gt;
&lt;TD&gt;90&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 3&lt;/TD&gt;
&lt;TD&gt;46&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 4&lt;/TD&gt;
&lt;TD&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 5&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 6&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB123&lt;/TD&gt;
&lt;TD&gt;Note 7&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BC234&lt;/TD&gt;
&lt;TD&gt;Note 1&lt;/TD&gt;
&lt;TD&gt;1065&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BC234&lt;/TD&gt;
&lt;TD&gt;Note 2&lt;/TD&gt;
&lt;TD&gt;456&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BC234&lt;/TD&gt;
&lt;TD&gt;Note 3&lt;/TD&gt;
&lt;TD&gt;231&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BC234&lt;/TD&gt;
&lt;TD&gt;Note 4&lt;/TD&gt;
&lt;TD&gt;153&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BC234&lt;/TD&gt;
&lt;TD&gt;Note 5&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BC234&lt;/TD&gt;
&lt;TD&gt;Note 6&lt;/TD&gt;
&lt;TD&gt;56&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 18:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501251#M133628</guid>
      <dc:creator>Sotarkadin</dc:creator>
      <dc:date>2018-10-03T18:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Top Values based on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501252#M133629</link>
      <description>&lt;P&gt;What if there is a five-way tie for third place.&amp;nbsp; What do you want to do with the 5 tied observations?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 19:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501252#M133629</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-03T19:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Top Values based on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501253#M133630</link>
      <description>&lt;P&gt;If there is a tie I would like just the first one of the ties.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 19:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501253#M133630</guid>
      <dc:creator>Sotarkadin</dc:creator>
      <dc:date>2018-10-03T19:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Top Values based on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501255#M133632</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Field $	field_value &amp;amp; $	cnt_val;
cards;
AB123	Note 1	100
AB123	Note 2	90
AB123	Note 3	46
AB123	Note 4	23
AB123	Note 5	12
AB123	Note 6	10
AB123	Note 7	5
BC234	Note 1	1065
BC234	Note 2	456
BC234	Note 3	231
BC234	Note 4	153
BC234	Note 5	100
BC234	Note 6	56
;

proc rank data=have out=want(where=(cnt_val_rank&amp;lt;=3)) ties=low descending;
   by field notsorted;
   var cnt_val ;
   ranks cnt_val_rank ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 19:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501255#M133632</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-03T19:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Top Values based on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501259#M133633</link>
      <description>&lt;P&gt;or just&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by field descending cnt_val; 
run;

data want;
do _n_=1 by 1 until( last.field);
set have;
by field ;
if _n_&amp;lt;=3 then output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 19:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501259#M133633</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-03T19:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Top Values based on other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501260#M133634</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;Thank you so much.&amp;nbsp; This worked perfectly.&amp;nbsp; I was trying to use the Rank function and was unable to get it to work properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 19:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-Values-based-on-other-variables/m-p/501260#M133634</guid>
      <dc:creator>Sotarkadin</dc:creator>
      <dc:date>2018-10-03T19:12:57Z</dc:date>
    </item>
  </channel>
</rss>

