使用sas proc转置将行拆分为两列

时间:2017-12-16 20:41:57

标签: sas transpose

我的数据集如下:

unit   A1  B1  A2 B2  A3  B3  ....
  .
  .
  .

我需要将其转换为:

unit   A   B
  1
  2
  3

我可以单独转置每个:

proc transpose data=test OUT=TESTOUT;
   var A1-A5 B1-B5;
   BY UNIT;

但这给了我一长列而不是2

1 个答案:

答案 0 :(得分:0)

proc transpose data=test out=test1(rename=(col1=dat));
by id;
var dat1-dat5;
run;

proc transpose data=test out=test2(rename=(col1=rec));
by id;
var rec1-rec5;
run;

data test3 (drop=_name_);
merge test1 test2;
by id;
run;