<?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: This post is part of the post &amp;quot;Need Urgent Help again!! Appreciate it.&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261852#M51032</link>
    <description>&lt;P&gt;I don't mind to explain. Consider n is the number of rows in the dataset sorted by ascending gdp. So rows 1 and 2 are the cities with the lowest gdp. Rows n-1 and n are the cities with the highest gdp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point= options allows access by rownumber. The statement with nobs= stores the number of rows in variable n but never actually gets executed due to the "if 0". This approach is very efficient. If you don't count the sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this explains my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2016 17:18:07 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-04-06T17:18:07Z</dc:date>
    <item>
      <title>Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261811#M51014</link>
      <description>&lt;P&gt;This post is part of the post "Need Urgent Help again!! Appreciate it."&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; &lt;STRONG&gt;ex&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;input City $ Region $ GDP;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;City1 E 11.1&lt;/P&gt;
&lt;P&gt;City2 E 12.5&lt;/P&gt;
&lt;P&gt;City3 E 5.5&lt;/P&gt;
&lt;P&gt;City4 A 8.5&lt;/P&gt;
&lt;P&gt;City5 A 9.5&lt;/P&gt;
&lt;P&gt;City6 A 10.5&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If want to get two largest gdp by city and two smallest gdp by city in one data set, how can I do it? Please advise me again. Thanks. I am a beginner to SAS and these problems takes me for 2 to 3 days to work it, but still I don't get it. I appreciate this forum and everyone's help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261811#M51014</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T16:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261819#M51018</link>
      <description>&lt;P&gt;Many ways to do this. This is quick and dirty (two passes of the data). Secret is in the OUTOBS option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ex;
input City $ Region $ GDP;
cards;
City1 E 11.1
City2 E 12.5
City3 E 5.5
City4 A 8.5
City5 A 9.5
City6 A 10.5
;
run;

proc sql outobs=2;
create table largest2 as

select city, gdp
from ex
order by gdp desc;

create table smallest2 as
select city, gdp
from ex
order by gdp;

quit;

data all;
set largest2 smallest2;
run;

proc print data=largest2;
run;

proc print data=smallest2;
run;

proc print data=all;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261819#M51018</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-06T16:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261823#M51020</link>
      <description>&lt;P&gt;anyothe ways not using proc sql? if so, please instruct me. Thanks a lot for your help, too.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261823#M51020</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T16:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261834#M51024</link>
      <description>&lt;P&gt;Shure why not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=ex;
    by gdp;
run;

data want;
    if 0 then set ex nobs=n;
    do i=1, 2, n-1, n;
        set ex point=i;
        output;
    end;
    stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261834#M51024</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-06T16:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261839#M51025</link>
      <description>&lt;P&gt;PROC SUMMARY/PROC MEANS (as suggested by Loko and KurtBremser in the other thread) allows for the "n largest/smallest" values as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=ex nway;
class region;
var GDP;
output out=want(drop=_:) idgrp(max(GDP) out[2] (GDP city)=highGDP city_highGDP)
                         idgrp(min(GDP) out[2] (GDP city)=lowGDP  city_lowGDP);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261839#M51025</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-06T16:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261841#M51026</link>
      <description>&lt;P&gt;I would opt for &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;'s solution, but FWIW, here is a data step solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ex;
	input City $ Region $ GDP;
	cards;
City1 E 11.1
City2 E 12.5
City3 E 5.5
City4 A 8.5
City5 A 9.5
City6 A 10.5
;
run;

proc sort data=ex;
	by region gdp;
run;

data want;
	do _s=1 by 1 until (last.region);
		set ex;
		by region gdp;

		if _s=1 then
			smallest_city=city;

		if _s=2 then
			second_smallest_city=city;
	end;

	do _l=1 by 1 until (last.region);
		set ex;
		by region gdp;

		if _l=_s then
			largest_city=city;

		if _l=_s-1 then
			second_largest_city=city;
	end;

	drop _: city gdp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261841#M51026</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-06T16:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261843#M51027</link>
      <description>&lt;P&gt;Hi Cathy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Welcome to programming in SAS. Here's a couple of hints for getting the appropriate response.&lt;/P&gt;
&lt;P&gt;Try and include a descriptive subject line for your problem. Saying you need immediate help isn't helpful for describing your problem. Everyone here has something that's an issue and that's why they're posting.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is good to link to your previous question if you've already asked it somewhere and the solution doesn't work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've modified your title here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your question provides sample data, but it doesn't show what you want the output to look like so we are guessing a bit. It helps if you provide sample output and input &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;You want the top 2 and bottom 2 from your dataset.&lt;/P&gt;
&lt;P&gt;The process is then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very simple way, and easily understood way is to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort ascending, and take the first two as smallest.&lt;/P&gt;
&lt;P&gt;Sort descending, and take the first two as largest&lt;/P&gt;
&lt;P&gt;Combine datasets.&lt;/P&gt;
&lt;P&gt;You can use the automatic variable _n_ as a pseudo row counter, and output explicitly tells SAS to keep those records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ex;
input City $ Region $ GDP;
cards;
City1 E 11.1
City2 E 12.5
City3 E 5.5
City4 A 8.5
City5 A 9.5
City6 A 10.5
;
run;

proc sort data=ex;
by gdp;
run;

data smallest;
set ex;
if _n_ &amp;lt;= 2 then output;
run;

proc sort data=ex;
by descending gdp;
run;

data largest;
set ex;
if _n_ &amp;lt;=2 then output;
run;

data want;
set smallest largest;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;A slightly more complex method is to use the NOBS variable &amp;nbsp;after you sort it. This is an automatic variable that allows you to know the number of observations in a dataset. Then in one pass you can take the top 2 (if _N_ &amp;lt;=2) and bottom two, (if _n_ &amp;gt;= NOBS-1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ex;
input City $ Region $ GDP;
cards;
City1 E 11.1
City2 E 12.5
City3 E 5.5
City4 A 8.5
City5 A 9.5
City6 A 10.5
;
run;

proc sort data=ex;
by gdp;
run;

data want;
set ex nobs=count; *store the nobs into a variable called count;

if _n_ &amp;lt;= 2 then output;

if _n_ &amp;gt;= count-1 then output;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261843#M51027</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-06T16:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261845#M51028</link>
      <description>&lt;P&gt;This is good one, but why you need to have n-1 and I don't understand the codes. Thanks.&amp;nbsp;&amp;nbsp;Would you mind to explain me?&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;ex&lt;/SPAN&gt; nobs&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
        &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;ex&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;point&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 16:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261845#M51028</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T16:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261847#M51029</link>
      <description>&lt;P&gt;Thanks a lot, I joined and registered the forum yesterday and I did not know how to post it. Thank you for your suggestion and correcting me.I appreciate it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 17:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261847#M51029</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T17:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261852#M51032</link>
      <description>&lt;P&gt;I don't mind to explain. Consider n is the number of rows in the dataset sorted by ascending gdp. So rows 1 and 2 are the cities with the lowest gdp. Rows n-1 and n are the cities with the highest gdp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point= options allows access by rownumber. The statement with nobs= stores the number of rows in variable n but never actually gets executed due to the "if 0". This approach is very efficient. If you don't count the sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this explains my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 17:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261852#M51032</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-06T17:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261855#M51033</link>
      <description>&lt;P&gt;Thank you Haikuo&amp;nbsp;&lt;SPAN class="login-bold"&gt;I appreciate for your help too.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 17:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261855#M51033</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T17:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261859#M51035</link>
      <description>&lt;P&gt;Thank you again. So if I have large data set, let's say I want 10 lowest and 10 largest, so I need to write from rows 1 to 10?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 17:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261859#M51035</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T17:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261860#M51036</link>
      <description>&lt;P&gt;Thank you very much for you input too. I appreciate it. I like your codes as well.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 17:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261860#M51036</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T17:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261861#M51037</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80016"&gt;@Cathy&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you again. So if I have large data set, let's say I want 10 lowest and 10 largest, so I need to write from rows 1 to 10?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have a variety of solutions provided, in your response we can't see which one you're referring to.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In mine, you can change the 2 to 10 and _N_-1 to _n_ - 9 and you'll be fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Proc Summary solution also scales well, change 2 to 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not all of the others do &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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 17:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261861#M51037</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-06T17:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261881#M51039</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80016"&gt;@Cathy﻿&lt;/a&gt;: Also, please note that some of the suggested solutions (including mine) select the two smallest and largest GDPs &lt;STRONG&gt;in each region&lt;/STRONG&gt;, as this was specified in &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Need-Urgent-Help-again-Appreciate-it/m-p/261725#M50976" target="_blank"&gt;your earlier post&lt;/A&gt;, whereas others select the &lt;STRONG&gt;overall&lt;/STRONG&gt; extreme values from the input dataset (maybe correctly, because you didn't write "in each region," but "by city" in the initial post of the current thread).&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 18:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261881#M51039</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-06T18:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261903#M51040</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 19:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261903#M51040</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T19:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261904#M51041</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;I want 2 smallest and largest only by city for this thread. yes, I needed to do by region for previous one. Thanks for clarification.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 19:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261904#M51041</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-06T19:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: This post is part of the post "Need Urgent Help again!! Appreciate it."</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261907#M51043</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80016"&gt;@Cathy﻿&lt;/a&gt;: Thanks for the clarification. In this case, you can omit the NWAY option and CLASS statement in&amp;nbsp;the PROC SUMMARY approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=ex;
var GDP;
output out=want(drop=_:) idgrp(max(GDP) out[2] (GDP city)=highGDP city_highGDP)
                         idgrp(min(GDP) out[2] (GDP city)=lowGDP  city_lowGDP);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2016 19:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261907#M51043</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-06T19:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261965#M51055</link>
      <description>&lt;PRE&gt;
Use proc univariate :




ods select none;
ods output ExtremeValues=want;
proc univariate data=sashelp.class nextrval=2 ;
class sex;
var age;
run;
ods select all;






&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 01:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/261965#M51055</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-07T01:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Top and bottom 2 by city using a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/262035#M51083</link>
      <description>&lt;P&gt;Good idea (as always) from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest a slight modification of his PROC UNIVARIATE approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output ExtremeObs=want;
proc univariate data=ex nextrobs=2;
*class region; /* commented out for overall extremes */
id city;
var gdp;
run;
ods select all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With &lt;FONT face="courier new,courier"&gt;ExtremeObs&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;nextrobs&lt;/FONT&gt; you obtain the &lt;EM&gt;n&lt;/EM&gt; (here: &lt;EM&gt;n&lt;/EM&gt;=2) highest/lowest &lt;EM&gt;observations&lt;/EM&gt;, whereas &lt;FONT face="courier new,courier"&gt;ExtremeValues&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;nextrval&lt;/FONT&gt; request the&amp;nbsp;&lt;EM&gt;n&lt;/EM&gt; &lt;SPAN&gt;highest/lowest &lt;EM&gt;values&lt;/EM&gt;. This means, if, for example, two cities&amp;nbsp;shared the&amp;nbsp;top rank with equal GDP values (say, GDP=15), followed by a city with GDP=13, the above step would yield the two GDP=15 cities and&amp;nbsp;would not&amp;nbsp;include GDP=13 (as the second highest &lt;EM&gt;value&lt;/EM&gt;). The ID statement includes variables City_Low and City_High in the WANT dataset to identify the cities with the extreme GDP values.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 10:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Top-and-bottom-2-by-city-using-a-data-step/m-p/262035#M51083</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-07T10:37:47Z</dc:date>
    </item>
  </channel>
</rss>

