<?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: rank scores by data step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493921#M72305</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184018"&gt;@Geo-&lt;/a&gt;&amp;nbsp;Is it some kind of &lt;STRONG&gt;&lt;U&gt;exclusive&lt;/U&gt; &lt;/STRONG&gt;datastep challenge? If so, I like it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id  Score ;
cards;
 1  3.50 
2  3.65
3  4.00
4  3.85
5  4.00
6  3.65 
;


data _null_;
call symputx('n',n);
set have nobs=n;
stop;
run;

data want;
do n=1 by 1 until(lr);
retain rank score;
set have end=lr;
array t(&amp;amp;n) ;
array k t&amp;amp;n-t1 ;
t(n)=score;
end;
call sortn(of k[*]);
score=t(1);
rank=1;
output;
do n=2 to dim(t);
if t(n) ne t(n-1) then rank+1;
score=t(n);
output;
end;
keep  score rank;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 09 Sep 2018 16:46:12 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-09T16:46:12Z</dc:date>
    <item>
      <title>rank scores by data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493904#M72302</link>
      <description>&lt;P&gt;To rank scores by data step, If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.&lt;/P&gt;&lt;PRE&gt;+----+-------+
| Id | Score |
+----+-------+
| 1  | 3.50  |
| 2  | 3.65  |
| 3  | 4.00  |
| 4  | 3.85  |
| 5  | 4.00  |
| 6  | 3.65  |
+----+-------+&lt;/PRE&gt;&lt;P&gt;For example, given the above&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;Scores&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;table, your query should generate the following report (order by highest score):&lt;/P&gt;&lt;PRE&gt;+-------+------+
| Score | Rank |
+-------+------+
| 4.00  | 1    |
| 4.00  | 1    |
| 3.85  | 2    |
|&amp;nbsp;3.65  | 3    |
| 3.65  | 3    |
| 3.50  | 4    |
+-------+------+&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Sep 2018 14:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493904#M72302</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-09-09T14:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: rank scores by data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493906#M72304</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;input Id  Score ;
cards;
 1  3.50 
2  3.65
3  4.00
4  3.85
5  4.00
6  3.65 
;

proc sort data=have;
by descending score;
run;

data want;
set have;by descending score;
retain rank;
if first.score then rank+1;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Sep 2018 14:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493906#M72304</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-09-09T14:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: rank scores by data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493921#M72305</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184018"&gt;@Geo-&lt;/a&gt;&amp;nbsp;Is it some kind of &lt;STRONG&gt;&lt;U&gt;exclusive&lt;/U&gt; &lt;/STRONG&gt;datastep challenge? If so, I like it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id  Score ;
cards;
 1  3.50 
2  3.65
3  4.00
4  3.85
5  4.00
6  3.65 
;


data _null_;
call symputx('n',n);
set have nobs=n;
stop;
run;

data want;
do n=1 by 1 until(lr);
retain rank score;
set have end=lr;
array t(&amp;amp;n) ;
array k t&amp;amp;n-t1 ;
t(n)=score;
end;
call sortn(of k[*]);
score=t(1);
rank=1;
output;
do n=2 to dim(t);
if t(n) ne t(n-1) then rank+1;
score=t(n);
output;
end;
keep  score rank;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Sep 2018 16:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493921#M72305</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-09T16:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: rank scores by data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493930#M72306</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id  Score ;
cards;
 1  3.50 
2  3.65
3  4.00
4  3.85
5  4.00
6  3.65 
;

data want;
if 0 then set have(rename=(score=_score));
   dcl hash H (dataset:'have(rename=(score=_score))',ordered:'d', multidata:'y') ;
   h.definekey  ("_score") ;
   h.definedata ('_score') ;
   h.definedone () ;
dcl hiter i('h');
do while(i.next()=0);
if _score ne score then rank+1;
score=_score;
output;
end;
stop;
keep rank score;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Sep 2018 17:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/rank-scores-by-data-step/m-p/493930#M72306</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-09T17:17:11Z</dc:date>
    </item>
  </channel>
</rss>

