在SAS中创建观察值组合

在SAS中创建观察值组合,sas,combinations,Sas,Combinations,我需要弄清楚如何将数据集中所有可能的数据组合制成表格。我有一个数据集,每个人有两行,一行表示活动分数,一行表示测试总分。每次就诊时的得分都有变量。一个人可能有1到5次就诊。我在寻找一个人的所有可能的分数组合 例如,下面是生成示例数据结构的代码 data example; input name $ type $ visit1-visit5; datalines; Bob activity 10 13 16 . . Bob total 13 19 17 . . J

我需要弄清楚如何将数据集中所有可能的数据组合制成表格。我有一个数据集,每个人有两行,一行表示活动分数,一行表示测试总分。每次就诊时的得分都有变量。一个人可能有1到5次就诊。我在寻找一个人的所有可能的分数组合

例如,下面是生成示例数据结构的代码

data example;
  input name $ type $ visit1-visit5;
    datalines;
    Bob activity 10 13 16 . .
    Bob total 13 19 17 . .
    John activity 11 20 25 20 21
    John total 13 15 17 19 22
    Steve activity 6 . . . .
    Steve total 9 . . . . .
    ;
run;
我希望有一个数据集,它能为我提供如下结构:

Bob activity 10 13
Bob activity 10 16
Bob activity 13 16
Bob total    13 19
Bob total    13 17
Bob total    19 17
John (rows for all possible combinations)
Steve - would have no rows, since he only has one visit (no combinations possible)

有什么建议吗?

对于N,选择2,您想要的输出结构和两个嵌套DO就足够了

data example;
   input name $ type $ visit1-visit5;
   datalines;
Bob activity 10 13 16 . .
Bob total 13 19 17 . .
John activity 11 20 25 20 21
John total 13 15 17 19 22
Steve activity 6 . . . .
Steve total 9 . . . . .
;;;;
   run;
data by2;
   set example;
   array v[*] visit:;
   n=n(of v[*]);
   do i = 1 to n;
      col1 = v[i];
      do j = i + 1 to n;
         col2 = v[j];
         output;
         end;
      end;
   drop i j visit:;
   run;
proc print;
   run;