<?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: Select top N data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332821#M74951</link>
    <description>&lt;P&gt;Your code wouldn't be recognized, by SAS, as being valid code. Conversely, the following would do what you want.&lt;/P&gt;
&lt;P&gt;When you run a querry using SAS proc sql, &amp;amp;sqlobs. contains the number of records in the file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*as an example I'm substituting sashelp.class for sas.t*/
proc sql noprint;
  create table final as
    select *
      from sashelp.class (rename=(name=EE
                                  age=RACE
                                  weight=SALARY))
        order by salary descending
  ;
quit;

data final (keep=EE RACE SEX SALARY);
  set final;
  if _n_/&amp;amp;sqlobs. gt .1 then stop;
  output;
run;

proc print;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2017 22:34:49 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-02-14T22:34:49Z</dc:date>
    <item>
      <title>Select top N data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332812#M74948</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am so new to SAS progam and need help with my codes below.&amp;nbsp; I am trying to find the top 10% of employees with highest salary.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA TOP10PS; SET SAS.T;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;SORT;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;BY&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DESCENDING&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SALARY;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EE1; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TOP10PS &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=EOF;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EOF &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;THEN&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FORMAT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TENP &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;COUNT=_N_;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;TENP = COUNT / &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; COUNT &amp;lt;= TENP &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;THEN&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;OUTPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;KEEP&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EE RACE SEX SALARY;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FINAL; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EE1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;PRINT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;N&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ID&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EE; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;VAR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; RACE SEX SALARY;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 22:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332812#M74948</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-14T22:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Select top N data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332818#M74949</link>
      <description>&lt;P&gt;Check out this thread &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;A href="https://communities.sas.com/t5/General-SAS-Programming/choose-top-10-percent-data-based-on-one-variable/td-p/272003" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/choose-top-10-percent-data-based-on-one-variable/td-p/272003&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 22:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332818#M74949</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-14T22:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Select top N data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332821#M74951</link>
      <description>&lt;P&gt;Your code wouldn't be recognized, by SAS, as being valid code. Conversely, the following would do what you want.&lt;/P&gt;
&lt;P&gt;When you run a querry using SAS proc sql, &amp;amp;sqlobs. contains the number of records in the file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*as an example I'm substituting sashelp.class for sas.t*/
proc sql noprint;
  create table final as
    select *
      from sashelp.class (rename=(name=EE
                                  age=RACE
                                  weight=SALARY))
        order by salary descending
  ;
quit;

data final (keep=EE RACE SEX SALARY);
  set final;
  if _n_/&amp;amp;sqlobs. gt .1 then stop;
  output;
run;

proc print;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 22:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332821#M74951</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-14T22:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Select top N data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332823#M74953</link>
      <description>Hello Art,&lt;BR /&gt;Thank you so much and very grateful for your assistance. ~Bonnary&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Feb 2017 22:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332823#M74953</guid>
      <dc:creator>BonnaryW</dc:creator>
      <dc:date>2017-02-14T22:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select top N data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332856#M74960</link>
      <description>&lt;P&gt;You could use proc rank to get the top decile first.&amp;nbsp; Then you can sort that&amp;nbsp;much smaller data set without further filtering.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=sas.t 
                out=final (where=(salary_decile=9)) 
                groups=10;
  var salary;
  ranks salary_decile;
run;

proc sort;
  by descending salary;
run;

proc print n;
  id ee;
  var race sex salary;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Feb 2017 01:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-top-N-data/m-p/332856#M74960</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-15T01:32:57Z</dc:date>
    </item>
  </channel>
</rss>

