Converting long table into sas table in SAS

时间:2015-06-30 13:51:49

标签: sas transpose

I am trying to convert a long table into wide table in SAS. I have the following data

Team ID Player  Score
1        Andy   12
2       Andy    32
1       Andy    2
3       Andy    0
1       Andy    43
3         Bin   33
1        Bin    23
3        Bin    34
3         Bin   3
1         Bin   12
2        Ray    34
3        Ray    52
2        Ray    11

Now I want to add score of each player teamwise like

Team ID Player  Score
1       Andy    46
1       Ray     34
1       Bin     33
2       Andy    43
2        Ray    52
3         Bin   72
3         Ray   11

Now I want to tanspose the players so that I get one row for each team like this.

Team ID Andy    Ray Bin
1        46     34  33
2        43     52  .
3          .    11  72

I tried with proc transpose and proc means but couldn't find a suitable solution. Will appreciate your help for a sas code.

Regards

1 个答案:

答案 0 :(得分:0)

这可能有用。首先按" Team":

对数据进行排序
Proc SORT Data=Have Out=Want1;
by Team;
Run;

然后转置您的数据,因为您的变量将被排序"由Team" (垂直)与" Id Player" (水平):

PROC TRANSPOSE Data=Want1 Out=Want2 let;
Id Player;
By Team;
Var Score;
Run;