DATA Step, Macro, Functions and more

How to Double Sort?

Reply
Frequent Contributor
Posts: 102

How to Double Sort?

Hi,

  1. I have a panel dataset (below is a small sample). I would like to sort the data independently by Uvalue, and Svalue into quartiles,

By independently, I mean if I use proc rank to output 4 ranks based on Uvalue, I do not consider Svalue. And vice versus if I output based on Svalue.

After the two sorts are done,

I expect 4 ranks within each variable category. 4*4 =16 cells,

My goal is to test whether Dvalue differs significantly within each cell.


2. That is does Dvalue in (Quartile 1 based on Uvalue rank) is significantly different from Dvalue in Quartile 1 based on Dvalue rank.

I know how to single sort, but need your help with double sort, and save the output for T-test in part 2.

thanks!

Lan

firmidyearUvalueSvalueDvalue
100119920.310100
100119930.61190
1001199411190
100119950.912100
100119961.112110
100119970.9212110
100119981.113111
100219930.2920
100219940.3922
100219950.49.123
100219960.91025
100219970.71030
100319951615
100319961.1515
100319971.4716
Respected Advisor
Posts: 4,930

Re: How to Double Sort?

Proc RANK does its own sorting for each variable. You don't have to worry about it. So the answer to your first question is straightforward. The second question however isn't valid statistically as the two sets that you want to compare are not independent. I would simply look at the frequency and Dvalue mean for each combination of quartiles :

proc rank data=have out=haveQuart groups=4;
var Uvalue Svalue;
ranks Uquart Squart;
run;

proc means data=haveQuart n mean nonobs printaltypes;
class Uquart Squart;
var Dvalue;
run;

PG

PG
Ask a Question
Discussion stats
  • 1 reply
  • 723 views
  • 1 like
  • 2 in conversation