Transposing wide to long in SAS, without extra columns

后端 未结 3 1464
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 07:48

I\'d like to transpose a dataset, but SAS insists on adding a new column, if the \"by\" column has multiple entries.

So if I run

data test;
    input a b         


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-25 08:14

    You can't use PROC TRANSPOSE in a single step with a 'mixed' dataset (multiple rows per by group AND multiple columns) to get long. Transpose only really works well going all one or the other.

    Easiest way to get long is usually the data step.

    data want;
     set test;
     array vars b c;
     do _i = 1 to dim(vars);
      varname = vname(vars[_i]);
      value   = vars[_i];
      output;
     end;
     keep a varname value;
    run;
    

提交回复
热议问题