SAS重组数据

时间:2018-11-23 20:46:11

标签: sas transpose

我需要帮助重组数据。我的桌子看起来像这样

 NameHead Department Per_test Per_Delta Per_DB Per_Vul  
 Nancy    Health     55       33.2      33     63  
 Jim      Air        25       22.8      23     11  
 Shu      Water      26       88.3      44     12   
 Dick     Electricity 77      55.9      66     10   
 Elena    General    88       22        67     9  
 Nancy    Internet   66       12        44     79   

我希望我的桌子看起来像这样

NameHead    Nancy   Jim    Shu      Dick        Elena    Nancy   
Department  Health  Air    Water    Electricity General Internet   
Per_test    55       25     26      77            88    66  
Per_Delta   33.2     22.8   88.3    55.9          22    12   
PerDB       33       23     44      66            67    44   
Per_Vul     63       11     12      10            9     79   

我尝试了proc换位,但无法获得所需的结果。请帮忙!

谢谢!

1 个答案:

答案 0 :(得分:0)

PROC TRANSPOSE完全可以满足您的需求。如果要包含字符变量,则必须包含VAR语句。

proc transpose data=have out=want;
  var _all_;
run;

请注意,您不能拥有没有名称的变量。这是数据集的样子。

Obs _NAME_            COL1         COL2         COL3         COL4         COL5         COL6

 1  NameHead      Nancy        Jim          Shu          Dick         Elena        Nancy
 2  Department    Health       Air          Water        Electricity  General      Internet
 3  Percent_test            55           25           26           77           88           66
 4  Percent_Delta         33.2         22.8         88.3         55.9           22           12
 5  Percent_DB              33           23           44           66           67           44
 6  Percent_Vul             63           11           12           10            9           79