SAS,转置表格

时间:2019-04-16 14:43:23

标签: sas transpose

我想将SAS表从数据Have转换为想要的数据。 我觉得我需要使用Proc转置,但无法弄清楚该怎么做。

data Have;
 input Stat$ variable_1 variable_2 variable_3 variable_4;
 datalines;
 MAX 6 7 11 23
 MIN 0 1 3  5
 SUM 29 87 30 100
;




data Want;
 input Variable $11.0 MAX MIN SUM;
 datalines;
 Variable_1 6 0 29  
 Variable_2 7 1 87
 Variable_3 11 3 87 
 Variable_4 23 5 100
;

1 个答案:

答案 0 :(得分:1)

你是对的,proc转置就是解决方案

data Have;
 input Stat$ variable_1 variable_2 variable_3 variable_4;
 datalines;
 MAX 6 7 11 23
 MIN 0 1 3  5
 SUM 29 87 30 100
;    

/*sort it by the stat var*/
proc sort data=Have; by Stat; run;

/*id statement will keep the column names*/
proc transpose data=have out=want name=Variable;
id stat;
run;

proc print data=want; run;