Hi Sam, Basically, the portion in paranthesis with the case/when I'm creating a new temporary variable (one that isn't kept for final dataset) and using it to order the dataset. Since you wanted to get 0,1,2,3 to lead and then from there reverse order by group, I've used a somewhat clever transformation of your ord variable to achieve the result. Your ORD variable is 0,1,2,...,n and thus GE 0 for all points. As such, I know that for all x,y in {1,2,...,n} if x > y then 1/x < 1/y. So using this transform allowed me to order all events with ord 4 or more as with the condition when (ord GE 4). Since I know that all such division is still always GE 0, I simply set "all other cases" (so effectively all cases where ORD LT 4) to 0. Since the new created temporary variable is applied 2nd in the order by statement, SQL orders the following pairs starting with the first element of the pair (1,0),(1, 1/5),(1, 1/9), (1, 1/13) (2,0),(2, 1/6),(2, 1/10), (2, 1/14) and so on. If you are more familiar with data step procedures, here's how it would've looked like data intermediate; set have; grp = mod(ord,4)+1; if (ord GE 4) then tempvar=1/ord; else tempvar=0; run; proc sort data=intermediate out=want(drop=tempvar); by grp tempvar; run; If you look at the tempvar column in the intermediate dataset, you will see what I've been trying to explain above. You can remove the (drop=tempvar) if you want to see it after the sort for learning purpose. I had gone with proc SQL because I believe it is slightly more efficient as the intermediate stuff needs not to be written on the disk. You won't see a difference if the dataset is small. Hope this helps. Vincent
... View more