BookmarkSubscribeRSS Feed
Doug____
Pyrite | Level 9

I am using PROC RANK with by group processing (pre-sorted). Even though the values are different, PROC RANK returns all 1s for the rank values. Many values are being ranked by the same by group processing. It does not happen with all variables, but it does occur with several of them. 

 

This is the list of example values for a parameter within a single by group (all are rank = 1 in the output dataset):

6.5

0

3.4

0.77777

0.33333

1

2

0

0

0.88888

2

0

0.666666

 

 

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Show us your code. Click on the running man icon and paste the code into the window that appears (DO NOT SKIP THIS STEP)

--
Paige Miller
Doug____
Pyrite | Level 9

proc rank data = CM_BY_FA_S out = CM_BY_FA_ORG_RANKS descending ties = low;

by Manager;

VAR 

Var1

Var2

Var3, etc.;

Ranks

Var1_R

Var2_R

Var3_R, etc.;

run;

 

NOTE: There were 48 observations read from the dataset WORK.CM_BY_FA_S.

NOTE: The data set WORK.CM_BY_FA_ORG_RANKS has 48 observations and 280 variables.

NOTE:  PROCEDURE RANK used (Total process time):

              real time                         0.15 seconds

              cpu time                         0.07 seconds

 

There are 140 variables to rank in the dataset. 

Reeza
Super User
Still don't get all 1s.

You can use this macro if you want to more easily get the ranks out:

https://gist.github.com/statgeek/7cffd06ebc3bc9c78b4f6a5b4538b053
Reeza
Super User
And the log please.
PeterClemmensen
Tourmaline | Level 20

Show us your code please.

Reeza
Super User

I cannot replicate your issue.

 

data have;
input X;
cards;
6.5
0
3.4
0.77777
0.33333
1
2
0
0
0.88888
2
0
0.666666
;;;;

proc rank data=have out=want groups=4;
var x;
Ranks x_rank;
run;

proc freq data=want;
table x_rank;
run;

Rank for Variable X
x_rank Frequency Percent Cumulative
Frequency
Cumulative
Percent
0 4 30.77 4 30.77
1 2 15.38 6 46.15
2 3 23.08 9 69.23
3 4 30.77 13 100.00

 


@Doug____ wrote:

I am using PROC RANK with by group processing (pre-sorted). Even though the values are different, PROC RANK returns all 1s for the rank values. Many values are being ranked by the same by group processing. It does not happen with all variables, but it does occur with several of them. 

 

This is the list of example values for a parameter within a single by group (all are rank = 1 in the output dataset):

6.5

0

3.4

0.77777

0.33333

1

2

0

0

0.88888

2

0

0.666666

 

 


 

Rick_SAS
SAS Super FREQ

The code you posted uses TIES=LOW. If you are getting all ranks equal to 1, that means that all values for a certain variable are the same. See the following example. The X variable is a constant column, so the ranks are always 1.

 

data Have;
set Sashelp.Class;
X = 99;
run;

proc rank data = Have out = CM_BY_FA_ORG_RANKS descending ties = low;
VAR   Height   Weight   Age   X;
Ranks Height_R Weight_R Age_R X_R;
run;

proc print;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1793 views
  • 2 likes
  • 5 in conversation