So using this dataset:
data swim;
input Name $ 1-7 Gender $ 9 Back 11-14 Free 16-19 Count 21-25;
datalines;
Andrea F 28.6 30.3 5
Carole F 32.9 24.0 3
Clayton M 27.0 21.9 7
Curtis M 29.0 22.6 1
Doug M 27.3 22.4 12
Ellen F 27.8 27.0 4
Jan F 31.3 31.2 3
Jimmy M 26.3 22.5 6
Karin F 34.6 26.2 7
Mick M 29.0 25.4 1
Richard M 29.7 30.2 2
Sam M 27.2 24.1 8
Susan F 35.1 36.1 10
;
proc rank data=swim_sort groups=3 out=ranked;
var back;
ranks rank;
run;
I want to rank swimmers based on their backstroke time. But I also want to put them in class 3 if their count is less than 3, if that makes sense.
So instead of this:
We get this:So the last 3 swimmers in class 1 are now in class 2 because their count was less than 3.
Is there a way to do that with proc rank, or do I need something else?
Thanks.
Include your condition into your ranking criteria:
data swim;
input Name $ 1-7 Gender $ 9 Back 11-14 Free 16-19 Count 21-25;
datalines;
Andrea F 28.6 30.3 5
Carole F 32.9 24.0 3
Clayton M 27.0 21.9 7
Curtis M 29.0 22.6 1
Doug M 27.3 22.4 12
Ellen F 27.8 27.0 4
Jan F 31.3 31.2 3
Jimmy M 26.3 22.5 6
Karin F 34.6 26.2 7
Mick M 29.0 25.4 1
Richard M 29.7 30.2 2
Sam M 27.2 24.1 8
Susan F 35.1 36.1 10
;
data altSwim;
set swim;
altBack = back + 100*(count<3);
run;
proc sort data=altSwim; by altBack; run;
proc rank data=altSwim groups=3 out=ranked(drop=altBack);
var altBack;
ranks rank;
run;
proc print data=ranked; run;
Include your condition into your ranking criteria:
data swim;
input Name $ 1-7 Gender $ 9 Back 11-14 Free 16-19 Count 21-25;
datalines;
Andrea F 28.6 30.3 5
Carole F 32.9 24.0 3
Clayton M 27.0 21.9 7
Curtis M 29.0 22.6 1
Doug M 27.3 22.4 12
Ellen F 27.8 27.0 4
Jan F 31.3 31.2 3
Jimmy M 26.3 22.5 6
Karin F 34.6 26.2 7
Mick M 29.0 25.4 1
Richard M 29.7 30.2 2
Sam M 27.2 24.1 8
Susan F 35.1 36.1 10
;
data altSwim;
set swim;
altBack = back + 100*(count<3);
run;
proc sort data=altSwim; by altBack; run;
proc rank data=altSwim groups=3 out=ranked(drop=altBack);
var altBack;
ranks rank;
run;
proc print data=ranked; run;
This looks perfect, I just want to double check that I understand what's going on.
So it's taking the original dataset, and if the count is less than 3, adding 100 to back in order to make it much larger, thus forcing it into rank 2.
Now if I wanted to make it do the opposite, and force them into rank 0, I could do something like altBack = back + -100*(count<3); ?
Right.
Putting them in the middle group would be more difficult!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.