Ranking data across several repeated measures

Reply
New Contributor
Posts: 4

Ranking data across several repeated measures

Hello all,

I am relatively new to SAS (please bear with me).

I have a data set with repeated measures for several variables. The data set looks (and is defined in the INPUT) like this:

subject     group     latency A     latency B     latency C

10                     1                     32                         8                             41

10                     1                     5                          188                          556

10                     1                     4                          83                            338

13                     2                     2                          3                              48

13                     2                     3                          3                              147

13                     2                     20                        42                             66

The 3 lines per subject represent repeated measures; so at test 1, latency A of subject 10 was 32, at test 2 it was 5, and at test 3 it was 4.

I would like to be able to rank ALL of the data in a latency class.

So the data set above would look like this:

subject     group     rank latency A    rank latency B     rank latency C

10                     1                     1                                     4                                       6

10                     1                     3                                     1                                       1

10                     1                     4                                     2                                       2

13                     2                     6                                     5.5                                    5

13                     2                     5                                     5.5                                    3

13                     2                     2                                      3                                      4

If I use the RANK procedure, I end up with the ranks per variable per testing session- meaning a number of ranks per variable equal to the number of test subjects, so all of the above would be ranked as "1"  or " 2".

Is there a way to include more lines in my ranking procedure? I think that this basically means combining variables, but I also need to be able to use the ranks for further analysis in which I need to know which rank belongs to which subject for which variable on which day. I don't think just combining the variables will do this- or I haven't been able to do so thus far.

Any ideas? I've consunted the experts I can physically talk to and come up empty handed. I've tried the search function and haven't found this question, so I'm hoping that for help through the discussion board.

Thanks!

Respected Advisor
Posts: 4,930

Re: Ranking data across several repeated measures

Posted in reply to RNUtrecht

I can only guess what you tried so far, but remove the BY statement from your RANK procedure and you should get what you want.

PG

PG
Super User
Posts: 11,343

Re: Ranking data across several repeated measures

Posted in reply to RNUtrecht

I think this builds the set you're looking for, adding new variables for the ranks as you never know when you need the raw values:

proc rank data=have out=want descending;

var latencyA latencyb latencyC;

ranks RankedA rankedb rankedC;

run;

New Contributor
Posts: 4

Re: Ranking data across several repeated measures

Thank you for the fast replies. This looks like what I need, ballardw. I'll update when I've tested to let you know if this gets me what I am looking for.

New Contributor
Posts: 4

Re: Ranking data across several repeated measures

Posted in reply to RNUtrecht

Hmm, I'm trying to get this to run but the syntax ballardw supplied still gets me a number of ranks equal to the number of subjects- so ranked per test session, not over test sessions.

Anyone with more ideas?

Respected Advisor
Posts: 2,655

Re: Ranking data across several repeated measures

Posted in reply to RNUtrecht

I ran 's code on the small data sample given, and get exactly what you want.  There must be more to the data than the sample, so please fill us in.

Steve Denham

New Contributor
Posts: 4

Re: Ranking data across several repeated measures

Posted in reply to RNUtrecht

OK, this is what I get for trying to ask for advice on a simplified data set.

My profound apologies, I put together the previous example data set incorrectly; the code Edward Ballard sent works on the sample data set but not on the actual data set.

This is a part of the actual data set:

OPTIONS NOCENTER NODATE PS=80 LS=130; DATA su_so_re;

INPUT

chick_no rearing_type genetic_strain pen arm_swapped leave_STBox_1

chick_no rearing_type genetic_strain pen arm_swapped leave_STBox_2

chick_no rearing_type genetic_strain pen arm_swapped leave_STBox_3;

DATALINES;

10 1 1 1 1 32

10 1 1 1 1 5

10 1 1 1 1 4

11 1 1 1 1 2

11 1 1 1 1 3

11 1 1 1 1 1

30 2 1 2 1 558

30 2 1 2 1 15

30 2 1 2 1 5

35 2 1 3 1 211

35 2 1 3 1 600

35 2 1 3 1 7 ;

PROC SORT;

BY rearing_type genetic_strain;

RUN;

proc rank data=su_so_re out=want descending;

var leave_STBox_1 leave_STBox_2 leave_STBox_3;

ranks r_leave_STBox_1 r_leave_STBox_2 r_leave_STBox_3;

run;

PROC PRINT;

RUN;

This gets me the following table of results:

Obs        chick_no              rearing_type      genetic_strain   pen        arm_swapped   leave_STBox_1 leave_STBox_2                leave_STBox_3 r_leave_STBox_1             r_leave_STBox_2             r_leave_STBox_3

1              10           1              1              1              1              32           5              4              3              3              3

2              11           1              1              1              1              2              3              1              4              4              4

3              30           2              1              2              1              558         15           5              1              2              2

4              35           2              1              3              1              211         600         7              2              1              1

This output is ranked by leave_STbox_1, leave_STbox2 and leave_STbox_3 separately, so the ranks are equal to the number of subjects (1-4; last 3 columns in output). What I would like for this data set is for the ranks for all 3 variables to be considered together, so that the ranks as shown in _leave_STBox_1, r_leave_STBox_2 and r_leave_STBox_3 are ranked 1-12 (3 observations, 4 subjects).

As a final note, I need the ranks to be identifiable as belonging to measure 1, 2, or 3 for each subject.

Again, apologies, and again the question if anyone has any idea how to do this.

Respected Advisor
Posts: 2,655

Re: Ranking data across several repeated measures

Posted in reply to RNUtrecht

I think you can get this pretty easily if you add one more variable to your input dataset.  A variable that serves as an indicator as to which measure would do this.

OPTIONS NOCENTER NODATE PS=80 LS=130;

DATA su_so_re;

INPUT

chick_no rearing_type genetic_strain pen arm_swapped leave_STBox measure;

DATALINES;

10 1 1 1 1 32 1

10 1 1 1 1 5 2

10 1 1 1 1 4 3

11 1 1 1 1 2 1

11 1 1 1 1 3 2

11 1 1 1 1 1 3

30 2 1 2 1 558 1

30 2 1 2 1 15 2

30 2 1 2 1 5 3

35 2 1 3 1 211 1

35 2 1 3 1 600 2

35 2 1 3 1 7  3

;

PROC SORT;

BY rearing_type genetic_strain chick_no measure;

RUN;

proc rank data=su_so_re out=want descending;

var leave_STBox ;

ranks r_leave_STBox;

run;

PROC PRINT;

RUN;

Now if you need ranks based on some subsets, such as ranks within rearing_type, you could add in a BY statement to the proc rank code.

Steve Denham

Ask a Question
Discussion stats
  • 7 replies
  • 386 views
  • 0 likes
  • 4 in conversation