<?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: proc rank (ties = mean) returning duplicates of the same rank in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583221#M166015</link>
    <description>Because you have ties....a value of 0 is a value of 0 and it will have the same rank as other 0s. Is there another way you'd like ties to be accounted for? You could just sort and create a counter but then you don't really have a true indication of the rank because does a rank of 15 mean anything if the rank of 14 and 16 have the same underlying value?</description>
    <pubDate>Thu, 22 Aug 2019 15:18:06 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-08-22T15:18:06Z</dc:date>
    <item>
      <title>proc rank (ties = mean) returning duplicates of the same rank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583055#M165944</link>
      <description>&lt;P&gt;I have this data:&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dat;
   input ID 10 domain rowpercent;
   datalines;
RZL34500 1 2.8
RZL34500 2 0.0
RZL34500 3 71.1
RZL34500 4 0.0
RZL34500 5 4.8
RZL34500 6 2.8
RZL34500 7 2.9
RZL34500 8 4.8
RZL34500 9 4.8
RZL34500 10 0.0
RZL34500 11 0.0
RZL34500 12 0.0
RZL34500 13 0.0
RZL34500 14 2.5
RZL34500 15 0.0
RZL34500 16 0.0
RZL34500 17 0.0
RZL34500 18 0.0
RZL34500 19 0.0
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;I am trying to rank it so that higher values are ranked higher:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc rank data=dat out=temp_1 ties=mean descending;
	by id;
	var RowPercent;
	ranks rank;
run;&lt;/PRE&gt;&lt;P&gt;My results are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ID	         domain rowpercent	rank
RZL34500	1	2.8	                 6.5
RZL34500	2	0	                 14
RZL34500	3	71.1	                 1
RZL34500	4	0	                 14
RZL34500	5	4.8	                 3
RZL34500	6	2.8	                 6.5
RZL34500	7	2.9	                 5
RZL34500	8	4.8	                 3
RZL34500	9	4.8	                 3
RZL34500	10	0	                 14
RZL34500	11	0	                 14
RZL34500	12	0	                 14
RZL34500	13	0	                 14
RZL34500	14	2.5	                 8
RZL34500	15	0	                 14
RZL34500	16	0	                 14
RZL34500	17	0	                 14
RZL34500	18	0	                 14
RZL34500	19	0	                 14&lt;/PRE&gt;&lt;P&gt;Why are there multiple '3's and '14's?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondary question: Is there a way that I can rank these values such that I get an accurate 'top 3'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 05:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583055#M165944</guid>
      <dc:creator>nathanleggett</dc:creator>
      <dc:date>2019-08-22T05:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc rank (ties = mean) returning duplicates of the same rank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583221#M166015</link>
      <description>Because you have ties....a value of 0 is a value of 0 and it will have the same rank as other 0s. Is there another way you'd like ties to be accounted for? You could just sort and create a counter but then you don't really have a true indication of the rank because does a rank of 15 mean anything if the rank of 14 and 16 have the same underlying value?</description>
      <pubDate>Thu, 22 Aug 2019 15:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583221#M166015</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-22T15:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc rank (ties = mean) returning duplicates of the same rank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583228#M166018</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286136"&gt;@nathanleggett&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First off a correction to your INPUT statement in order to make the DATA step work:&lt;/P&gt;
&lt;PRE&gt;input ID &lt;STRONG&gt;&lt;FONT color="#008000"&gt;:$&lt;/FONT&gt;&lt;/STRONG&gt;10&lt;STRONG&gt;&lt;FONT color="#008000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt; domain rowpercent;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286136"&gt;@nathanleggett&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;Why are there multiple '3's and '14's?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;[As Reeza has pointed out already:] This is because there are tied observations, i.e. groups of observations with the same ROWPERCENT value, and PROC RANK assigns the same rank to all observations within a group. For instance, the 2nd, 3rd and 4th largest value are 4.8 so that each of them is assigned rank 3, the &lt;EM&gt;average&lt;/EM&gt; of 2, 3 and 4 because you specified &lt;FONT face="courier new,courier"&gt;ties=&lt;EM&gt;mean&lt;/EM&gt;&lt;/FONT&gt;.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;
&lt;P&gt;Secondary question: Is there a way that I can rank these values such that I get an accurate 'top 3'?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sure, but you need to decide how to handle the ties. For example, you could select all observations with the top three &lt;EM&gt;values&lt;/EM&gt; by using&lt;/P&gt;
&lt;PRE&gt;proc rank data=dat out=temp_1&lt;FONT color="#008000"&gt;(where=(rank&amp;lt;=3))&lt;/FONT&gt; ties=&lt;FONT color="#008000"&gt;dense&lt;/FONT&gt; descending;&lt;/PRE&gt;
&lt;P&gt;and then restrict dataset TEMP_1 to three observations in a subsequent step if needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use a different procedure instead of PROC RANK:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;E.g., PROC SUMMARY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=dat;
by id;
var rowpercent;
output out=top3(drop=_:) idgrp (max(rowpercent) out[3] (rowpercent domain)=) / autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(There are options to modify the handling of ties.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or PROC UNIVARIATE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output extremeobs=top3obs(drop=low: varname);
proc univariate data=dat nextrobs=3;
by id;
var rowpercent;
run;
ods select all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(A variant of this could select the top three &lt;EM&gt;values&lt;/EM&gt;&amp;nbsp;[disregarding multiplicities] rather than the top three observations.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 15:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-rank-ties-mean-returning-duplicates-of-the-same-rank/m-p/583228#M166018</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-08-22T15:25:34Z</dc:date>
    </item>
  </channel>
</rss>

