SAS Proc Transpose

作者: 不连续小姐 | 来源:发表于2019-08-22 02:54 被阅读2次

    SAS Day 42: Proc Transpose
    Proc Transpose is a powerful procedure for reshaping the data structures (i.e.Row observations to Column Variables or Vice Versa).

    Key options: VAR, BY, ID, Prefix, name

    Basic Proc Transpose Syntax:

    proc transpose data=adsl out=a(rename=(sex=label)) prefix=col; 
    id trt1; 
    var count; 
    by x; 
    run;
    
    [caption id="attachment_2691" align="alignnone" width="1024"] image

    Monsterkoi / Pixabay[/caption]

    A classical example is to select the treatment group in ADSL by sex.

    Current Data Structure:

    image

    Sample Transposed Data Structure 1: separate treatment count BY Label

    image

    Sample Code 1:

    proc sort data=c nodupkey;
    by label treatment;
    run;
    
    proc transpose data=c out=d(drop=_name_) prefix=treat; 
    id treatment; 
    var count; 
    by label ;
    run;
    

    Sample Transposed Data Structure 2: Separate sex count BY treatment

    image

    Sample Code 2:

    proc sort data=c nodupkey;
    by treatment label;
    run;
    
    proc transpose data=c out=d(drop=_name_) prefix=sex; 
    id label; 
    var count; 
    by treatment ;
    run;
    

    Note: the transpose data need to sort in the "by" variable order before applying Proc Transpose.

    Little Trick: we use ID option to prevent the case when a "BY" group is empty.

    🐸Happy SAS Coding!

    相关文章

      网友评论

        本文标题:SAS Proc Transpose

        本文链接:https://www.haomeiwen.com/subject/boqgsctx.html