<?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: Growth rate and ranking in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365670#M86879</link>
    <description>&lt;P&gt;Post test data in the form of a datastep!!&lt;/P&gt;
&lt;P&gt;Well, this should give you an idea (note the rank is in reverse):&lt;/P&gt;
&lt;PRE&gt;data have;
  input YEAR ID Growth_Rate;
datalines;
1963 1 1
1964 1 2
1965 1 2
1966 1 3
1967 1 0.5
1968 1 5
1969 1 6
1970 1 7
;
run;

data want;
  set have;
  array rank{5} 8.;
  rank{1}=lag1(growth_rate);
  rank{2}=lag2(growth_rate);
  rank{3}=lag3(growth_rate);
  rank{4}=lag4(growth_rate);
  rank{5}=lag5(growth_rate);
  call sortn(of rank:);
run;
&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Jun 2017 13:50:49 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-06-09T13:50:49Z</dc:date>
    <item>
      <title>Growth rate and ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365661#M86877</link>
      <description>&lt;P&gt;Hello, dear experts.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I have a problem related to ranking growth rate in sas.&amp;nbsp;&lt;BR /&gt;I have computed growth rate as annual growth rate. The thing that I want to do next is to rank the previous 5 year growth rate, given the year of formation, which starts in 1968. Can someone please help me? I would be very thankful. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data have:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;YEAR &amp;nbsp; ID &amp;nbsp; Growth Rate&lt;/P&gt;&lt;P&gt;1963 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1%&lt;BR /&gt;1964 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2%&lt;BR /&gt;1965 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2%&lt;BR /&gt;1966 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3%&lt;BR /&gt;1967 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0,5%&lt;BR /&gt;1968 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5%&lt;BR /&gt;1969 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6%&lt;BR /&gt;1970 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7%&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Data want:&lt;/P&gt;&lt;P&gt;YEAR &amp;nbsp; ID &amp;nbsp; Growth Rate &amp;nbsp;RANK1 &amp;nbsp;RANK2 RANK3 RANK4 RANK5&lt;/P&gt;&lt;P&gt;1963 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;1964 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2%&lt;BR /&gt;1965 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2%&lt;BR /&gt;1966 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3%&lt;BR /&gt;1967 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0,5%&lt;BR /&gt;1968 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2% &amp;nbsp; &amp;nbsp; &amp;nbsp; 1% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0,5%&lt;BR /&gt;1969 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2% &amp;nbsp; &amp;nbsp; &amp;nbsp; 2% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0,5%&lt;BR /&gt;1970 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3% &amp;nbsp; &amp;nbsp; &amp;nbsp; 2% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0,5%&lt;BR /&gt;&lt;BR /&gt;This is just an example, by orginal want file has many years, IDs, and growth rates.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I also wonder about what to do with "tied" ranks, like the 2% in both.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 13:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365661#M86877</guid>
      <dc:creator>TorTheHammer</dc:creator>
      <dc:date>2017-06-09T13:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Growth rate and ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365670#M86879</link>
      <description>&lt;P&gt;Post test data in the form of a datastep!!&lt;/P&gt;
&lt;P&gt;Well, this should give you an idea (note the rank is in reverse):&lt;/P&gt;
&lt;PRE&gt;data have;
  input YEAR ID Growth_Rate;
datalines;
1963 1 1
1964 1 2
1965 1 2
1966 1 3
1967 1 0.5
1968 1 5
1969 1 6
1970 1 7
;
run;

data want;
  set have;
  array rank{5} 8.;
  rank{1}=lag1(growth_rate);
  rank{2}=lag2(growth_rate);
  rank{3}=lag3(growth_rate);
  rank{4}=lag4(growth_rate);
  rank{5}=lag5(growth_rate);
  call sortn(of rank:);
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 13:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365670#M86879</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-09T13:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Growth rate and ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365697#M86888</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input YEAR ID Growth_Rate;
datalines;
1963 1 1
1964 1 2
1965 1 2
1966 1 3
1967 1 0.5
1968 1 5
1969 1 6
1970 1 7
;
run;

data want;
  set have;
  array rank{5} rank5-rank1;
  array r{0:4} _temporary_;
  if _n_ gt 5 then do;
   do i=1 to 5;
    rank{i}=r{i-1};
   end;
   call sortn(of rank{*});
  end;
  r{mod(_n_,5)}=Growth_Rate;
 drop i;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 14:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365697#M86888</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-09T14:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Growth rate and ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365714#M86896</link>
      <description>Hello, thank you for a solid answer!&lt;BR /&gt;The code does what I want, but I have a struggle related to "by" groups. For example if I have two ID's, then one's growth_rate jumps over to another ones ID. I tried to use "by" statement, but this doesn't solve the problem. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Fri, 09 Jun 2017 15:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365714#M86896</guid>
      <dc:creator>TorTheHammer</dc:creator>
      <dc:date>2017-06-09T15:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Growth rate and ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365756#M86914</link>
      <description>&lt;P&gt;You may need an if as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input YEAR ID Growth_Rate;
datalines;
1963 1 1
1964 1 2
1965 1 2
1966 1 3
1967 1 0.5
1968 1 5
1969 1 6
1970 1 7
;
run;

data want;
  set have;&lt;BR /&gt;  by id;
  array rank{5} 8.;&lt;BR /&gt;  if first.id then call missing(of rank:);
  if id=lag1(id) then rank{1}=lag1(growth_rate);
  if id=lag2(id) then rank{2}=lag2(growth_rate);
  if id=lag3(id) then rank{3}=lag3(growth_rate);
  if id=lag4(id) then rank{4}=lag4(growth_rate);
  if id=lag5(id) then rank{5}=lag5(growth_rate);
  call sortn(of rank:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 16:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Growth-rate-and-ranking/m-p/365756#M86914</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-09T16:11:52Z</dc:date>
    </item>
  </channel>
</rss>

