- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am struggling with what I would consider an easy thing, but I just cant get it done.
I've got something like
A B
1222 180.00
1222 180.00
1222 260.00
And I want...
A B RF_RANK
1222 180.00 1
1222 180.00 2
1222 260.00 3
What I get is
A B RF_RANK
1222 180.00 3
1222 180.00 3
1222 260.00 1
with this code:
proc rank data = work.W62KKV70
out = work.W62KKN4Z
descending
ties = high; // also tried DENSE and MEAN and LOW
by
TEC_POSITION_ID
;
var RATINGFAKTOR;
ranks RF_RANK;
run;
How would I get a sequential rank here?
Thanks a lot!
Thomas
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are getting descending values because you are asking for them. Your choice of ranks appears to be quite arbitrary, with ties being ranked according to location in the data.
For what you want, you didn't even need to run proc rank .. you just had to sort the data and then assign sequential numbers as ranks.
That is all I basically did with the code, below, except I used your proc rank statement rather than just a sort.
proc rank data = work.W62KKV70
out = work.W62KKN4Z;
by TEC_POSITION_ID;
var RATINGFAKTOR;
ranks RF_RANK;
run;
data work.W62KKN4Z;
set work.W62KKN4Z (drop=RF_RANK);
by TEC_POSITION_ID
if first.TEC_POSITION_ID then RF_RANK=1;
else RF_RANK+1;
run;
But you would have gotten the same result with:
proc sort data = work.W62KKV70
out = work.W62KKN4Z;
by TEC_POSITION_ID ratingfaktor;
run;
data work.W62KKN4Z;
set work.W62KKN4Z;
by TEC_POSITION_ID
if first.TEC_POSITION_ID then RF_RANK=1;
else RF_RANK+1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are getting descending values because you are asking for them. Your choice of ranks appears to be quite arbitrary, with ties being ranked according to location in the data.
For what you want, you didn't even need to run proc rank .. you just had to sort the data and then assign sequential numbers as ranks.
That is all I basically did with the code, below, except I used your proc rank statement rather than just a sort.
proc rank data = work.W62KKV70
out = work.W62KKN4Z;
by TEC_POSITION_ID;
var RATINGFAKTOR;
ranks RF_RANK;
run;
data work.W62KKN4Z;
set work.W62KKN4Z (drop=RF_RANK);
by TEC_POSITION_ID
if first.TEC_POSITION_ID then RF_RANK=1;
else RF_RANK+1;
run;
But you would have gotten the same result with:
proc sort data = work.W62KKV70
out = work.W62KKN4Z;
by TEC_POSITION_ID ratingfaktor;
run;
data work.W62KKN4Z;
set work.W62KKN4Z;
by TEC_POSITION_ID
if first.TEC_POSITION_ID then RF_RANK=1;
else RF_RANK+1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yay, of course
Thanks a lot Art!
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am not aware that Proc Rank is capable of doing this. When it run into tied values, it ranks them the SAME regardless, because they are TIED. Those different options of tie= do not change this.
Now in addition to Art's solution, you can also take advantage of _n_ to do the job:
data have;
input A B ;
cards;
1222 180.00
1222 180.00
1222 260.00
1223 1
1223 4
1224 2
1224 5
1224 5
1224 5
;
proc sort data=have;
by a b;
run;
data want;
do _n_=1 by 1 until (last.a);
set have;
by a;
Rank=_n_;
output;
end;
run;
proc print;run;
Regards,
Haikuo