如果您在中
SAS,请使用
PROC TRANSPOSE此选项。
PROCSQL;尽管许多
SQL变体都有自己的数据透视方式,
SAS并且已经
PROCTRANSPOSE并且希望您使用它,但是没有特别好的方法来执行此操作。
SAS数据步骤也可以非常高效地执行此操作,甚至可能比更好
PROC TRANSPOSE。这是一个示例,包括创建注释中提到的视图。
data want/view=want;set have;array vars a b c d; *array of your columns to transpose;do _t = 1 to dim(vars); *iterate over the array (dim(vars) gives # of elements); if not missing(vars[_t]) then do; *if the current array element's value is nonmissing; col1=vname(vars[_t]); *then store the variable name from that array element in a var; col2=vars[_t]; *and store the value from that array element in another var; output; *and finally output that as a new row; end;end;drop a b c d _t; *Drop the old vars (cols) and the dummy variable _t;run;



