<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56229#M12005</link>
    <description>try this...&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
&lt;BR /&gt;
create table rank_dist_before as&lt;BR /&gt;
&lt;BR /&gt;
select product, metric,lbl,ttype,dist,sum(sls) as sls&lt;BR /&gt;
&lt;BR /&gt;
from tmp1&lt;BR /&gt;
&lt;BR /&gt;
group by dist,ttype&lt;BR /&gt;
&lt;BR /&gt;
order by dist,ttype,sls descending;&lt;BR /&gt;
&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data rank_dist_nation;&lt;BR /&gt;
set rank_dist_before;&lt;BR /&gt;
by dist ttype descending sls ;&lt;BR /&gt;
if first.dist then rank = 0;&lt;BR /&gt;
Rank+1;&lt;BR /&gt;
retain rank;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 27 Jul 2010 18:47:26 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-07-27T18:47:26Z</dc:date>
    <item>
      <title>Ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56224#M12000</link>
      <description>ttype has two values 'MTH' and 'YTD'.if we want to display ranks of districts on these two values (grouping) such that we see how districts are ranked in a month and how they are ranked in year?&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
The below code gives ranks from 1 to 66 .instead we need rank 1 to 33 in mth and 1 to 33 in year to be shown in a single dataset&lt;BR /&gt;
proc sql;&lt;BR /&gt;
&lt;BR /&gt;
create table rank_dist_before as&lt;BR /&gt;
&lt;BR /&gt;
select product, metric,lbl,ttype,dist,sum(sls) as sls&lt;BR /&gt;
&lt;BR /&gt;
from tmp1&lt;BR /&gt;
&lt;BR /&gt;
group by dist,ttype&lt;BR /&gt;
&lt;BR /&gt;
order by sls descending;&lt;BR /&gt;
&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data rank_dist_nation;&lt;BR /&gt;
   set rank_dist_before;&lt;BR /&gt;
   Rank+1;&lt;BR /&gt;
 run;</description>
      <pubDate>Tue, 27 Jul 2010 16:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56224#M12000</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-07-27T16:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56225#M12001</link>
      <description>Hi:&lt;BR /&gt;
  If you are assigning the RANK variable in a program, this would be a good point to investigate BY group processing and the use of FIRST.&lt;I&gt;byvar&lt;/I&gt; logic (also LAST.byvar).&lt;BR /&gt;
 &lt;BR /&gt;
 cynthia&lt;BR /&gt;
&lt;BR /&gt;
ps...there is also a PROC RANK procedure that you might be able to use here -- I don't use it much, but perhaps someone else can help you with it.</description>
      <pubDate>Tue, 27 Jul 2010 16:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56225#M12001</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-27T16:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56226#M12002</link>
      <description>modify the DATA step to include a BY statement and explicitly reset the retain'd variable.&lt;BR /&gt;
&lt;BR /&gt;
data rank_dist_nation;&lt;BR /&gt;
set rank_dist_before;&lt;BR /&gt;
BY sls;&lt;BR /&gt;
IF first.sls THEN rank=0;&lt;BR /&gt;
RETAIN rank;&lt;BR /&gt;
Rank+1;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 27 Jul 2010 16:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56226#M12002</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-07-27T16:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56227#M12003</link>
      <description>I tried Proc rank,but it gives me  the same rank for all rows.</description>
      <pubDate>Tue, 27 Jul 2010 16:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56227#M12003</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-07-27T16:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56228#M12004</link>
      <description>1 is assigned to all rows.</description>
      <pubDate>Tue, 27 Jul 2010 16:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56228#M12004</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-07-27T16:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56229#M12005</link>
      <description>try this...&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
&lt;BR /&gt;
create table rank_dist_before as&lt;BR /&gt;
&lt;BR /&gt;
select product, metric,lbl,ttype,dist,sum(sls) as sls&lt;BR /&gt;
&lt;BR /&gt;
from tmp1&lt;BR /&gt;
&lt;BR /&gt;
group by dist,ttype&lt;BR /&gt;
&lt;BR /&gt;
order by dist,ttype,sls descending;&lt;BR /&gt;
&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data rank_dist_nation;&lt;BR /&gt;
set rank_dist_before;&lt;BR /&gt;
by dist ttype descending sls ;&lt;BR /&gt;
if first.dist then rank = 0;&lt;BR /&gt;
Rank+1;&lt;BR /&gt;
retain rank;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 27 Jul 2010 18:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ranking/m-p/56229#M12005</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-27T18:47:26Z</dc:date>
    </item>
  </channel>
</rss>

