如何在SAS中对数据集进行排序以使记录交错?

Ban*_*jer 1 sas

假设我有一个数据集:

data animals;
   input animal  $
         group   $
         control $;
datalines;
dog A c1
dog B c1
dog C c1
dog D c2
dog E c2
dog F c2
dog G c3
dog H c3
dog I c3
;
run;
Run Code Online (Sandbox Code Playgroud)

我希望以这样的方式对其进行排序,使得结果数据集看起来像:

dog A c1
dog D c2
dog G c3
dog B c1
dog E c2
dog H c3
dog C c1
dog F c2
dog I c3
Run Code Online (Sandbox Code Playgroud)

我没有看到任何特殊的proc排序选项会进行"交替"排序,因此我可能不得不对我的数据集"BY控制"进行子集化,然后在数据步骤中以它们交错/交替的方式重新组合.

有任何想法吗?谢谢.

Lau*_*els 7

proc sort data= animals out= animals2;
    by control group;
run;

data animals2;
    set animals2;
    by control;
    retain orderWithinControlType;
    if first.control then orderWithinControlType = 1;
    else orderWithinControlType +1;
run;

proc sort data= animals2 out= animals3;
    by orderWithinControlType control;
run;

proc print data= animals3;
run;
Run Code Online (Sandbox Code Playgroud)