<?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: How SAS assign rank while the number of obs less than number of groups? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-SAS-assign-rank-while-the-number-of-obs-less-than-number-of/m-p/724147#M224826</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the GROUPS= option the values of variable RANK_ aren't really ranks, but &lt;EM&gt;group numbers&lt;/EM&gt; defined by the formula&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;floor(rank*k/(n+1))&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;where &lt;FONT face="courier new,courier"&gt;rank&lt;/FONT&gt; is the rank that you would obtain without the GROUPS= option, &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; is the value specified in the GROUPS= option and (since you use the default TIES=MEAN) &lt;FONT face="courier new,courier"&gt;n&lt;/FONT&gt; is the number of observations with nonmissing values of your analysis variable AMIHUD (see &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p16s2o8e4bnqrin1phywxdaxqba7.htm&amp;amp;locale=en#n0ap7rle6oq6fon1209x0i7085jq" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in your example the ranks &lt;FONT face="courier new,courier"&gt;r = 1, 2, ..., 12, 13&lt;/FONT&gt; are transformed into &lt;FONT face="courier new,courier"&gt;floor(r*100/14) = 7, 14, ..., 85, 92&lt;/FONT&gt;.&lt;/P&gt;</description>
    <pubDate>Sat, 06 Mar 2021 10:57:01 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-03-06T10:57:01Z</dc:date>
    <item>
      <title>How SAS assign rank while the number of obs less than number of groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-SAS-assign-rank-while-the-number-of-obs-less-than-number-of/m-p/724142#M224822</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Today I try to use PROC rank in my project, due to the characteristic, I need to rank 100 groups per year per country. However, in this year in this country, there are only 13 observation, I am quite surprise that SAS can assign some numbers over there. Can I ask how SAS can assign these rank_ numbers?&lt;/P&gt;
&lt;P&gt;The value of variable need to be ranked&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;amihud
0.0005088943
1.4387286E-6
5.767935E-6
5.3867482E-7
2.1144515E-6
4.2862647E-6
0.0001175097
8.5303028E-6
0.000117864
3.4827424E-6
0.0000313065
0.0000173605
8.5760194E-6&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the result is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rank_
92
14
42
7
21
35
78
50
85
28
71
64
57&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How come SAS rank 92 or 42 while there are only 13 obs over there.&lt;/P&gt;
&lt;P&gt;Warm regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P/S: I think it is quite a bit irrelevant but my code is as below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=work.trim_price groups=100 out=temp;
		  by LOC year;
                   Comment LOC  is country;
		  var amihud;
		  ranks rank_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Mar 2021 10:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-SAS-assign-rank-while-the-number-of-obs-less-than-number-of/m-p/724142#M224822</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-06T10:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: How SAS assign rank while the number of obs less than number of groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-SAS-assign-rank-while-the-number-of-obs-less-than-number-of/m-p/724147#M224826</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the GROUPS= option the values of variable RANK_ aren't really ranks, but &lt;EM&gt;group numbers&lt;/EM&gt; defined by the formula&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;floor(rank*k/(n+1))&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;where &lt;FONT face="courier new,courier"&gt;rank&lt;/FONT&gt; is the rank that you would obtain without the GROUPS= option, &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; is the value specified in the GROUPS= option and (since you use the default TIES=MEAN) &lt;FONT face="courier new,courier"&gt;n&lt;/FONT&gt; is the number of observations with nonmissing values of your analysis variable AMIHUD (see &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=p16s2o8e4bnqrin1phywxdaxqba7.htm&amp;amp;locale=en#n0ap7rle6oq6fon1209x0i7085jq" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in your example the ranks &lt;FONT face="courier new,courier"&gt;r = 1, 2, ..., 12, 13&lt;/FONT&gt; are transformed into &lt;FONT face="courier new,courier"&gt;floor(r*100/14) = 7, 14, ..., 85, 92&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Mar 2021 10:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-SAS-assign-rank-while-the-number-of-obs-less-than-number-of/m-p/724147#M224826</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-06T10:57:01Z</dc:date>
    </item>
  </channel>
</rss>

