<?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 proc sort and select 10 largest values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/266377#M52490</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to select the top 10 obs with largest "amount" variable. Using the code belwo, sorting is done, but I still got the whole set, not the first 10 obs. What could be the problem that "obs=10" did not work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=have out=top_10 (obs=10);
by descending amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Apr 2016 14:00:03 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-04-26T14:00:03Z</dc:date>
    <item>
      <title>proc sort and select 10 largest values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/266377#M52490</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to select the top 10 obs with largest "amount" variable. Using the code belwo, sorting is done, but I still got the whole set, not the first 10 obs. What could be the problem that "obs=10" did not work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=have out=top_10 (obs=10);
by descending amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2016 14:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/266377#M52490</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-04-26T14:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and select 10 largest values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/266414#M52508</link>
      <description>&lt;P&gt;From the online documentation onthe OBS=Data set option:&lt;/P&gt;
&lt;TABLE cellspacing="2" cellpadding="4"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD align="right" class="label"&gt;Restriction:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockDark"&gt;Use with &lt;STRONG&gt;input&lt;/STRONG&gt; data sets only&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort you data and then use&lt;/P&gt;
&lt;P&gt;Data top_10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set top_10 (obs=10);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 15:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/266414#M52508</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-26T15:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and select 10 largest values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/500910#M133470</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* You can refer to this sample code and modify according to your needs..! */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* To find top 10 actual sales for each country from the SAShelp.prdsal2 dataset. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=sashelp.prdsal2 out = class;&lt;BR /&gt;by country descending actual;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set class;&lt;BR /&gt;by country;&lt;BR /&gt;if first.country = 1 then cnt = 0;&lt;BR /&gt;cnt + 1;&lt;BR /&gt;if cnt &amp;lt;= 10;&lt;BR /&gt;if last.country = 1 then cnt = 0;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 19:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/500910#M133470</guid>
      <dc:creator>SukritMehta</dc:creator>
      <dc:date>2018-10-02T19:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and select 10 largest values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/500967#M133495</link>
      <description>&lt;P&gt;Or use &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt; to sort, together with its &lt;FONT face="courier new,courier"&gt;outobs&lt;/FONT&gt;= option&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 21:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/500967#M133495</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-02T21:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and select 10 largest values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/532593#M145950</link>
      <description>&lt;P&gt;This is very close to what I am looking for but what if I want the top 10 by Jurisdiction and also by Date.&lt;BR /&gt;&lt;BR /&gt;This is my sample code for top 10 by Jurisdiction&lt;/P&gt;&lt;P&gt;proc sort data=ATM_TOP_VALUE out = ATM_TOP_VALUE1;&lt;BR /&gt;by Jurisdiction descending amount;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data ATM_TOP_VALUE2;&lt;BR /&gt;set ATM_TOP_VALUE1;&lt;BR /&gt;by Jurisdiction;&lt;BR /&gt;if first.Jurisdiction = 1 then cnt = 0;&lt;BR /&gt;cnt + 1;&lt;BR /&gt;if cnt &amp;lt;= 10;&lt;BR /&gt;if last.Jurisdiction = 1 then cnt = 0;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;However there is a field called month of and I want the top 10 for each jurisdiction for each month. How would I have to change the above code to get that?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 15:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/532593#M145950</guid>
      <dc:creator>orb204</dc:creator>
      <dc:date>2019-02-04T15:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and select 10 largest values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/532906#M146068</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259846"&gt;@orb204&lt;/a&gt;&amp;nbsp;and&amp;nbsp;welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just insert variable &lt;FONT face="courier new,courier"&gt;month&lt;/FONT&gt; as the second BY variable and use &lt;FONT face="courier new,courier"&gt;first.month&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;first.Jurisdiction&lt;/FONT&gt; to indicate where the counter is to be reset to zero:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=atm_top_value out=atm_top_value1;
by jurisdiction month descending amount;
run;

data atm_top_value2;
set atm_top_value1;
by jurisdiction month;
if first.month then cnt = 0;
cnt + 1;
if cnt &amp;lt;= 10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Note that I also simplified the code a bit.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;General recommendation:&lt;/U&gt; For quicker answers please open a new thread when you have a question. Only a few people will notice that an old thread (like this from October 2018 or actually even April 2016) has been continued. If you want to refer to an old thread, you can provide a hyperlink like this:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/500910" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/500910&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 12:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-select-10-largest-values/m-p/532906#M146068</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-02-05T12:23:16Z</dc:date>
    </item>
  </channel>
</rss>

