aha
aha

Reputation: 21

Proc Rank-whole dataset

I am trying to create ranks for 2 variables, which I will then sum to create a score.

Issue: I need to rank the whole dataset (i.e. into k quantile groups where k=n).

I'm using proc rank right now to calculate the rank for 1 variable. The variable is called first and I want to generate the rank called firstrank.

    proc rank data = moo  out= outmoo;
      var firstrank;
    run;

My output looks like

                                 Obs   first       firstrank
                                 1     0.000        9.5
                                 2     0.000        9.5
                                 3     0.000        9.5
                                 4     0.000        9.5
                                 5     0.000        9.5
                                 6     0.000        9.5
                                 7     0.000        9.5
                                 8     0.000        9.5
                                 9     0.000        9.5
                                10     0.000        9.5
                                11     0.000        9.5
                                12     0.000        9.5
                                13     0.000        9.5
                                14     0.000        9.5
                                15     0.000        9.5
                                16     0.000        9.5
                                17     0.000        9.5
                                18     0.000        9.5
                                19     0.105       19.5
                                20     0.105       19.5
                                21     0.210       23.5
                                22     0.210       23.5
                                23     0.210       23.5
                                24     0.210       23.5
                                25     0.210       23.5
                                26     0.210       23.5

As you can see the ranks are being averaged across ties in the variable first.

What I am trying to achieve is that all the values where first=0, firstrank=1, and first=0.105, firstrank=2, and so on.

Is there a way using SAS proc rank to do this? Or is there another proc to do this?

Upvotes: 0

Views: 586

Answers (1)

Joe
Joe

Reputation: 63434

If I understand your question, you need the TIES=DENSE option (or CONDENSE, its alias). See the documentation on PROC RANK.

data test;
  do x = 1 to 8;
    do y = 1 to 3;
      output;
    end;
  end;
run;

proc rank data=test out=want ties=dense;
var x;
ranks r;
run;

Upvotes: 2

Related Questions