Previous Page | Next Page

The RANK Procedure

Example 2: Ranking Values within BY Groups


Procedure features:

PROC RANK statement options:

DESCENDING

TIES=

BY statement

RANKS statement

VAR statement

Other features:

PRINT procedure


This example performs the following actions:


Program

 Note about code
options nodate pageno=1 linesize=80 pagesize=60;
 Note about code
data elect;
   input Candidate $ 1-11 District 13 Vote 15-18 Years 20;
   datalines;
Cardella    1 1689 8
Latham      1 1005 2
Smith       1 1406 0
Walker      1  846 0
Hinkley     2  912 0
Kreitemeyer 2 1198 0
Lundell     2 2447 6
Thrash      2  912 2
;
 Note about code
proc rank data=elect out=results ties=low descending;
 Note about code
   by district;
 Note about code
   var vote years;
   ranks VoteRank YearsRank;
run;
 Note about code
proc print data=results n;
   by district;
   title 'Results of City Council Election';
run; 

Output: Listing

 Note about figure
                        Results of City Council Election                       1

---------------------------------- District=1 ----------------------------------

                                                    Vote    Years
               Obs    Candidate    Vote    Years    Rank     Rank

                1     Cardella     1689      8        1       1  
                2     Latham       1005      2        3       2  
                3     Smith        1406      0        2       3  
                4     Walker        846      0        4       3  

                                     N = 4


---------------------------------- District=2 ----------------------------------

                                                     Vote    Years
              Obs    Candidate      Vote    Years    Rank     Rank

               5     Hinkley         912      0        3       3  
               6     Kreitemeyer    1198      0        2       3  
               7     Lundell        2447      6        1       1  
               8     Thrash          912      2        3       2  

                                     N = 4

Previous Page | Next Page | Top of Page