RANK Procedure

Example 1: Ranking Values of Multiple Variables

Features:
PROC RANK statement options:
DESCENDING
TIES=

RANKS statement

VAR statement

Other features:

PRINT procedure

Details

This example performs the following actions:
  • reverses the order of the ranks so that the highest value receives the rank of 1
  • assigns the best possible rank to tied values
  • creates ranking variables and prints them with the original variables

Program

options nodate pageno=1 linesize=80 pagesize=60;
data cake;
   input Name $ 1-10 Present 12-13 Taste 15-16;
   datalines;
Davis      77 84
Orlando    93 80
Ramey      68 72
Roe        68 75
Sanders    56 79
Simms      68 77
Strickland 82 79
;
proc rank data=cake out=order descending ties=low;
   var present taste;
   ranks PresentRank TasteRank;
run;
proc print data=order;
   title "Rankings of Participants' Scores";
run;

Program Description

Set the SAS system options. The NODATE option specifies to omit the date and time when the SAS job begins. The PAGENO= option specifies the page number for the next page of output that SAS produces. The LINESIZE= option specifies the line size. The PAGESIZE= option specifies the number of lines for a page of SAS output.
options nodate pageno=1 linesize=80 pagesize=60;
Create the CAKE data set. This data set contains each participant's last name, score for presentation, and score for taste in a cake-baking contest.
data cake;
   input Name $ 1-10 Present 12-13 Taste 15-16;
   datalines;
Davis      77 84
Orlando    93 80
Ramey      68 72
Roe        68 75
Sanders    56 79
Simms      68 77
Strickland 82 79
;
Generate the ranks for the numeric variables in descending order and create the output data set ORDER. DESCENDING reverses the order of the ranks so that the high score receives the rank of 1. TIES=LOW gives tied values the best possible rank. OUT= creates the output data set ORDER.
proc rank data=cake out=order descending ties=low;
Create two new variables that contain ranks. The VAR statement specifies the variables to rank. The RANKS statement creates two new variables, PresentRank and TasteRank, that contain the ranks for the variables Present and Taste, respectively.
   var present taste;
   ranks PresentRank TasteRank;
run;
Print the data set. PROC PRINT prints the ORDER data set. The TITLE statement specifies a title.
proc print data=order;
   title "Rankings of Participants' Scores";
run;

Output: Listing

                        Rankings of Participants' Scores                       1

                                                    Present    Taste
           Obs    Name          Present    Taste      Rank      Rank

            1     Davis            77        84        3         1
            2     Orlando          93        80        1         2
            3     Ramey            68        72        4         7
            4     Roe              68        75        4         6
            5     Sanders          56        79        7         3
            6     Simms            68        77        4         5
            7     Strickland       82        79        2         3