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

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: 

rank_snip.JPGWe get this:rank_snip2.JPGSo 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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

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;
PG
jl1005
Obsidian | Level 7

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); ?

PGStats
Opal | Level 21

Right.

 

Putting them in the middle group would be more difficult! Smiley Happy

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 1508 views
  • 3 likes
  • 2 in conversation