SAS:数据透视表proc制表或proc转置

时间:2019-11-05 11:49:44

标签: sas transpose tabulate

我的数据当前组织为:

NAME     COLOR PROFILE  HEIGHT
K2000    RED      C     5.10 
K2001    WHITE    B     7.11 
K2001    BLACK    B     5.12 
K2001    BLUE     B     5.2 
K2002    BLUE     A     9.3 
K2002    RED      A     8.2 
K2006    WHITE    D     5.5 
K2007    WHITE    A     8.6 
K2007    BLUE     A     5.7 
K2009    WHITE    D     8.8 
K2010    BLACK    B     5.9 
K2011    RED      B     9.6 
K2012    RED      C     7.7 
K2012    BLUE     C     9.6 
K2012    WHITE    C     7.5 
K2012    BLACK    C     8.9 

我希望它看起来像:

NAME  PROFILE  RED    WHITE BLACK BLUE
K2000    C     5.10                
K2001    B            7.11  5.12  5.2 
K2002    A     8.2                9.3 
K2006    D            5.5           
K2007    A            8.6         5.7 
K2009    D            8.8           
K2010    B                  5.9      
K2011    B     9.6                  
K2012    C     7.7    7.5   8.9   9.6 

此致

2 个答案:

答案 0 :(得分:0)

data I_HAVE;
    infile datalines truncover firstobs=2;
    input
        @01 NAME    $5.
        @10 COLOR   $4.
        @19 PROFILE $1.
        @25 HEIGHT  4.2
        ;
    datalines;
----+----1----+----2----+----3
K2000    RED      C     5.10 
K2001    WHITE    B     7.11 
K2001    BLACK    B     5.12 
K2001    BLUE     B     5.2 
K2002    BLUE     A     9.3 
K2002    RED      A     8.2 
K2006    WHITE    D     5.5 
K2007    WHITE    A     8.6 
K2007    BLUE     A     5.7 
K2009    WHITE    D     8.8 
K2010    BLACK    B     5.9 
K2011    RED      B     9.6 
K2012    RED      C     7.7 
K2012    BLUE     C     9.6 
K2012    WHITE    C     7.5 
K2012    BLACK    C     8.9 
;

proc transpose data=I_HAVE out=I_NEED;
    by NAME PROFILE;
    id COLOR;
    var HEIGHT;
run;

答案 1 :(得分:0)

如果您要使用PROC TABULATE进行报告,请采用以下方法

    proc tabulate data=have;
        class name profile color;
        var height;
        table name*profile,
              height=''*color=''*sum=''*f=best.;
    run;