<?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: Ranking a variable while accounting for subgroup in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319819#M9185</link>
    <description>Thank you!</description>
    <pubDate>Sun, 18 Dec 2016 21:21:54 GMT</pubDate>
    <dc:creator>r4321</dc:creator>
    <dc:date>2016-12-18T21:21:54Z</dc:date>
    <item>
      <title>Ranking a variable while accounting for subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319787#M9183</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of firms across multiple years. I'm trying to rank them by their size&amp;nbsp;while accounting for year. Firms would change their rankings each year according to how much their size changed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, made up data for illustration:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;year &amp;nbsp; firm &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;size &amp;nbsp; &amp;nbsp; &amp;nbsp; rank&lt;/P&gt;&lt;P&gt;1997 &amp;nbsp;Walmart &amp;nbsp; &amp;nbsp; 2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1997 &amp;nbsp;Microsoft &amp;nbsp; 3000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1997 &amp;nbsp;GM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1998 &amp;nbsp;Walmart &amp;nbsp; &amp;nbsp; 3000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1998 &amp;nbsp;Microsoft &amp;nbsp; &amp;nbsp;2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1998 &amp;nbsp;GM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1999 &amp;nbsp;Walmart &amp;nbsp; &amp;nbsp; 2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1999 &amp;nbsp;Microsoft &amp;nbsp; &amp;nbsp;1000 &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;1999 &amp;nbsp;GM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im sure the code is quite simple, but I've gotten hung up on it and couldnt find a solution. If anyone could help, I'd appreciate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Dec 2016 06:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319787#M9183</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2016-12-18T06:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking a variable while accounting for subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319790#M9184</link>
      <description>&lt;P&gt;Consider that there is no rank variable in your dataset. Then sort by year and descending size, this will sort the firms by year and size and brings the firm with more size to the top. Then we could derive the rank as below&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 year descending size;
run;

data want;
set have;
by year descending  size;
retain rank;
if first.year then rank=1;
else rank=rank+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Dec 2016 06:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319790#M9184</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-18T06:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking a variable while accounting for subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319819#M9185</link>
      <description>Thank you!</description>
      <pubDate>Sun, 18 Dec 2016 21:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319819#M9185</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2016-12-18T21:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking a variable while accounting for subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319834#M9186</link>
      <description>&lt;PRE&gt;

Or try PROC RANK.


data have;
input year   firm     : $20.       size ;
cards;
1997  Walmart     2000       2
1997  Microsoft   3000       1
1997  GM            1000       3
1998  Walmart     3000       1
1998  Microsoft    2000       2
1998  GM            1000       3
1999  Walmart     2000       2
1999  Microsoft    1000      3
1999  GM            3000        1
;
run;

proc rank data=have out=want  descending;
by year;
var size;
ranks rank;
run;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Dec 2016 02:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Ranking-a-variable-while-accounting-for-subgroup/m-p/319834#M9186</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-19T02:56:06Z</dc:date>
    </item>
  </channel>
</rss>

