2017-10-11 29 views
0

我认为这很容易,但我无法摆脱困境。SAS:作为变量组的观察 - 转置

我有一组名为变量,然后日期变量和一个值变量:

GROUP Date Value 
A 1-1-2010 1 
A 2-1-2010 2 
A 3-1-2010 3 
A 4-1-2010 4 
B 1-1-2010 5 
B 2-1-2010 6 
B 3-1-2010 7 
B 4-1-2010 8 
C 1-1-2010 9 
C 2-1-2010 10 
C 3-1-2010 11 
C 4-1-2010 12 

我现在想的是

Date  A B C 
1-1-2010 1 5 9 
2-1-2010 2 6 10 
3-1-2010 3 7 11 
4-1-2010 4 8 12 

我试图PROC转,但它不会让我因为小组有一次以上的重复观察。

任何想法表示赞赏

回答

0

您可以轻松地proc sql做到这一点 - 如果你事先知道所有组:

proc sql; 
    select date, 
      max(case when group = 'A' then value end) as A, 
      max(case when group = 'B' then value end) as B, 
      max(case when group = 'C' then value end) as C 
    from t 
    group by date; 
+0

为什么你会这样做?你必须提前知道这些团体?为什么不使用TRANSPOSE?它很容易处理。 – DomPazz

0

你可以使用PROC TRANSPOSE,你只需要适当的事情排序:

proc sort data=have out=temp; 
by date group; 
run; 

然后移调

proc transpose data=temp out=want; 
by date; 
id group; 
var value; 
run;