<?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: Rank Observations and Output Ties in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548396#M152062</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= have ;
by gender  descending score;
run;

data want (where=(rank le 2) drop= lag_score);
	set have;
	retain rank;
	lag_score=lag(score);
	by gender  descending score;
	if first.gender then rank = 1 ; 
    else do;	 
		if score=lag_score then rank + 0;
		else rank +1 ;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Apr 2019 04:02:30 GMT</pubDate>
    <dc:creator>34reqrwe</dc:creator>
    <dc:date>2019-04-04T04:02:30Z</dc:date>
    <item>
      <title>Rank Observations and Output Ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548373#M152052</link>
      <description>&lt;P&gt;Hi! I need your help to output the Top 2 scores, including ties, from this dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Have*/&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input name $ gender $ score;&lt;BR /&gt;cards;&lt;BR /&gt;Ann F 100&lt;BR /&gt;May F 100&lt;BR /&gt;Jean F 90&lt;BR /&gt;Leah F 89&lt;BR /&gt;Felix M 100&lt;BR /&gt;Chris M 95&lt;BR /&gt;Greg M 90&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Output Top 2 for Each Gender, Including Ties*/&lt;BR /&gt;data want;&lt;BR /&gt;input name $ gender $ score;&lt;BR /&gt;cards;&lt;BR /&gt;Ann F 100&lt;BR /&gt;May F 100&lt;BR /&gt;Jean F 90&lt;BR /&gt;Felix M 100&lt;BR /&gt;Chris M 95&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 01:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548373#M152052</guid>
      <dc:creator>angeliquec</dc:creator>
      <dc:date>2019-04-04T01:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Rank Observations and Output Ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548396#M152062</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= have ;
by gender  descending score;
run;

data want (where=(rank le 2) drop= lag_score);
	set have;
	retain rank;
	lag_score=lag(score);
	by gender  descending score;
	if first.gender then rank = 1 ; 
    else do;	 
		if score=lag_score then rank + 0;
		else rank +1 ;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 04:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548396#M152062</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-04-04T04:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Rank Observations and Output Ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548397#M152063</link>
      <description>&lt;P&gt;If your data is already sorted by gender and you don't mind creating a new variable :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have out=want(where=(_order&amp;lt;=2)) ties=dense descending;
by gender;
var score;
ranks _order;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 04:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548397#M152063</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-04T04:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Rank Observations and Output Ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548398#M152064</link>
      <description>&lt;P&gt;Or, if like me, you prefer to avoid the lag functions:&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 gender descending score;
run;

data want;
do until(last.gender);
    set have; by gender descending score;
    order = sum(order, first.score);
    if order &amp;lt;= 2 then output;
    end;
drop order;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 04:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548398#M152064</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-04T04:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rank Observations and Output Ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548402#M152066</link>
      <description>&lt;P&gt;You are right, the lag is not needed. out of interest why do you avoid lag functions - performance reasons or something else?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 04:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548402#M152066</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-04-04T04:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Rank Observations and Output Ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548409#M152071</link>
      <description>&lt;P&gt;Because they are not true lag functions but rather ill-designed FIFO queue functions. I mostly feel unsafe programming with those.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 04:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rank-Observations-and-Output-Ties/m-p/548409#M152071</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-04T04:52:25Z</dc:date>
    </item>
  </channel>
</rss>

