在 SAS 中将 long table 转换为 sas table

Converting long table into sas table in SAS

我正在尝试在 SAS 中将长 table 转换为宽 table。我有以下数据

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

现在我想像

一样按团队方式添加每个球员的得分
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

现在我想把球员并置,这样我就可以像这样为每支球队排成一行。

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

我尝试使用 proc 转置和 proc 方法,但找不到 suitable 解决方案。感谢您对 sas 代码的帮助。

此致

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

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

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

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