SAS Software for Learning Community

Welcome to the exclusive online community for all SAS learners.
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Lilik
Fluorite | Level 6

Good day dear All,

I am new here. Taking SAS courses and have a question regarding the Rank procedure. The thing is, when I'm using it my ranking values are not integres. 

I want to rank the goals quantities in order to find the second highest values of each category. 

Lilik_0-1742382049629.png

proc rank data=LaLiga out=rankings;
var goals;
ranks result;
proc print data=rankings;
run;

Lilik_1-1742382200397.png

why it doesn't work here?

thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I want to rank the goals quantities in order to find the second highest values of each category. 

 

If "category" means Position, then you want to make position a BY variable.

 

proc sort data=have;
    by position;
run;
proc rank data=have out=rankings descending ties=low;
    by position;
    var goals;
    ranks goals_ranked;
run;

 

As stated,  you will have to figure out which option of TIES= works best for you.

 

If you don't care about ties, then just sort the data by position and goals, and take the 2nd record for each position.

--
Paige Miller

View solution in original post

6 REPLIES 6
JackieJ_SAS
SAS Employee
Hi, The ranks are not integers, because of the ways tied values are being handled. When you have more than one observation with the same data value, the default is for PROC RANK to compute the mean of the ranks.

Try out different values of the TIES= option on the PROC RANK statement, and see which one gets what you want:

https://go.documentation.sas.com/doc/en/pgmsascdc/v_060/proc/p16s2o8e4bnqrin1phywxdaxqba7.htm#n128ut...

Since it looks like this is data where a higher number of goals is better, also consider using the DESCENDING option.
Lilik
Fluorite | Level 6

Thank you.

PaigeMiller
Diamond | Level 26

I want to rank the goals quantities in order to find the second highest values of each category. 

 

If "category" means Position, then you want to make position a BY variable.

 

proc sort data=have;
    by position;
run;
proc rank data=have out=rankings descending ties=low;
    by position;
    var goals;
    ranks goals_ranked;
run;

 

As stated,  you will have to figure out which option of TIES= works best for you.

 

If you don't care about ties, then just sort the data by position and goals, and take the 2nd record for each position.

--
Paige Miller
Lilik
Fluorite | Level 6

Thank you for your help.

Ksharp
Super User
proc rank data=have out=rankings descending ties=dense;
Lilik
Fluorite | Level 6
Thank you for your help.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 965 views
  • 5 likes
  • 4 in conversation