<?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: Control number of Output following Proc sort in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276612#M55439</link>
    <description>&lt;P&gt;Hi Deepak,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm afraid you cannot do that in proc sort. I checked and obs= and firstobs= just don't work. Surprisingly the options are silently ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I said, sort will have to create the entire table before s subset base on rownumbercan be determined. So it is not much of a&amp;nbsp; matter of efficiency to have a datastep as follow-up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jun 2016 20:51:03 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-06-10T20:51:03Z</dc:date>
    <item>
      <title>Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276605#M55433</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;Can somebody guide me to control the number of output following proc sort. Number of input can be controlled by firstobs and obs in proc sort. I want to control the number of record in my output.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id weight;
datalines;
1 10
2 20
3 30
4 20
5 30
;
run;

proc sort data =test (firstobs=1 obs=4) out =test1; by weight; run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276605#M55433</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-10T20:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276606#M55434</link>
      <description>&lt;P&gt;Proc sort will have to sort the entire table before determining the first n rows. So a subsequent datastep to achive that would not be much overhead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data =test out =test1; 
   by weight; 
run;

data test2;
   set test1 (firstobs=4 obs=7);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Alternatively, if you just want the top n rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=10;
   create table test2
     as select * from test
     order by weight;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276606#M55434</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-10T20:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276609#M55437</link>
      <description>&lt;P&gt;Hi Jklaverstijn,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you for your prompt reply. Regarding use of sql to control the number of output, I am already aware of. That is why, I have specifically mentioned about the proc sort step. I want to avoid additional data step following proc sort. In other word, I want to control my output within proc sort itself.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you in advance for your kindly guidance to move forward.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Deepak&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276609#M55437</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-10T20:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276611#M55438</link>
      <description>&lt;P&gt;Why not SQL?&lt;/P&gt;
&lt;P&gt;Why not use a succeeding data step?&lt;/P&gt;
&lt;P&gt;Motivate!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276611#M55438</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-06-10T20:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276612#M55439</link>
      <description>&lt;P&gt;Hi Deepak,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm afraid you cannot do that in proc sort. I checked and obs= and firstobs= just don't work. Surprisingly the options are silently ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I said, sort will have to create the entire table before s subset base on rownumbercan be determined. So it is not much of a&amp;nbsp; matter of efficiency to have a datastep as follow-up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276612#M55439</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-10T20:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276613#M55440</link>
      <description>&lt;P&gt;The only way I know to do this is with the undocumented function MONOTONIC. MONOTONIC() returns 1 on the first call and increases by 1 every time it is called. So, to keep the first two obs from proc sort (or any other proc) output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=test out=test1(where=(monotonic()&amp;lt;=2)); by weight; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276613#M55440</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-10T20:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276615#M55441</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=test out=test1(where=(monotonic()&amp;lt;=2)); by weight; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What I like is the cleverness. What I like less is the obscure character of monotonic(). It is undocumented for a reason. Eg, I am uncertain if it works reliably in a threaded environment. So your mileage may vary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 20:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276615#M55441</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-10T20:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276618#M55443</link>
      <description>&lt;P&gt;Maybe a WHERE= dataset option on the output dataset is even better than enforcing a fixed number of observations, because in case of ties the selection might be a bit arbitrary otherwise:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=test out=test1(where=(weight&amp;gt;=30));
by weight; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Drawback: You have to know a reasonable threshold value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or check&amp;nbsp;PROC UNIVARIATE with the NEXTROBS= option (I learned about this from &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261965#M51055" target="_blank"&gt;one of Ksharp's posts&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output ExtremeObs=check;
proc univariate data=test nextrobs=2;
id id;
var weight;
run;
ods select all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another approach&amp;nbsp;would&amp;nbsp;be&amp;nbsp;PROC SUMMARY with the IDGROUP option of the OUTPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to select the n largest/smallest &lt;EM&gt;values&lt;/EM&gt;&amp;nbsp;(as opposed to extreme &lt;EM&gt;observations&lt;/EM&gt;), you can use&amp;nbsp;PROC UNIVARIATE with the NEXTRVAL= option&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 21:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276618#M55443</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-06-10T21:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276622#M55446</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12460"&gt;@jklaverstijn&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Deepak,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm afraid you cannot do that in proc sort. I checked and obs= and firstobs= just don't work. Surprisingly the options are silently ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not at all "silent", from the documentation:&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="shortDesc"&gt;Specifies the last observation that SAS processes in a data set.&lt;/SPAN&gt;&lt;/P&gt;
&lt;H1&gt;&lt;A name="a000131154" target="_blank"&gt;&lt;/A&gt;OBS= Data Set Option&lt;/H1&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;SPAN class="shortDesc"&gt;&lt;BR /&gt;&lt;SPAN class="shortDesc"&gt;Specifies the last observation that SAS processes in a data set.&lt;/SPAN&gt;&lt;/SPAN&gt;&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;Valid in:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockDark"&gt;DATA step and PROC steps&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD align="right" class="label"&gt;Category:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockDark"&gt;Observation Control&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD align="right" class="label"&gt;Default:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockDark"&gt;MAX&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD align="right" class="label"&gt;Restriction:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockDark"&gt;&lt;STRONG&gt;Use with input data sets only&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD align="right" class="label"&gt;Restriction:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockDark"&gt;
&lt;P&gt;Cannot use with PROC SQL views&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;</description>
      <pubDate>Fri, 10 Jun 2016 21:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276622#M55446</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-10T21:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276631#M55448</link>
      <description>&lt;P&gt;I would prefer to get something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;NOTE: Dataset option OBS= is ignored for output datasets.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 22:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276631#M55448</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-10T22:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276672#M55463</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;Just desire to explore alternative and keep enthusiasm.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jun 2016 10:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276672#M55463</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-11T10:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Control number of Output following Proc sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276674#M55464</link>
      <description>&lt;P&gt;Hi Jan,&lt;/P&gt;&lt;P&gt;Thanks for your kind reply. It is helpful to me.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jun 2016 10:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Control-number-of-Output-following-Proc-sort/m-p/276674#M55464</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-11T10:38:26Z</dc:date>
    </item>
  </channel>
</rss>

