BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_NZ
Barite | Level 11

Hi all SAS Users,

 

Today I try to use PROC rank in my project, due to the characteristic, I need to rank 100 groups per year per country. However, in this year in this country, there are only 13 observation, I am quite surprise that SAS can assign some numbers over there. Can I ask how SAS can assign these rank_ numbers?

The value of variable need to be ranked

amihud
0.0005088943
1.4387286E-6
5.767935E-6
5.3867482E-7
2.1144515E-6
4.2862647E-6
0.0001175097
8.5303028E-6
0.000117864
3.4827424E-6
0.0000313065
0.0000173605
8.5760194E-6

And the result is

rank_
92
14
42
7
21
35
78
50
85
28
71
64
57

How come SAS rank 92 or 42 while there are only 13 obs over there.

Warm regards,

 

P/S: I think it is quite a bit irrelevant but my code is as below

proc rank data=work.trim_price groups=100 out=temp;
		  by LOC year;
                   Comment LOC  is country;
		  var amihud;
		  ranks rank_;
run;
Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Phil_NZ,

 

Because of the GROUPS= option the values of variable RANK_ aren't really ranks, but group numbers defined by the formula

floor(rank*k/(n+1))

where rank is the rank that you would obtain without the GROUPS= option, k is the value specified in the GROUPS= option and (since you use the default TIES=MEAN) n is the number of observations with nonmissing values of your analysis variable AMIHUD (see documentation).

 

So, in your example the ranks r = 1, 2, ..., 12, 13 are transformed into floor(r*100/14) = 7, 14, ..., 85, 92.

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hi @Phil_NZ,

 

Because of the GROUPS= option the values of variable RANK_ aren't really ranks, but group numbers defined by the formula

floor(rank*k/(n+1))

where rank is the rank that you would obtain without the GROUPS= option, k is the value specified in the GROUPS= option and (since you use the default TIES=MEAN) n is the number of observations with nonmissing values of your analysis variable AMIHUD (see documentation).

 

So, in your example the ranks r = 1, 2, ..., 12, 13 are transformed into floor(r*100/14) = 7, 14, ..., 85, 92.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1387 views
  • 2 likes
  • 2 in conversation