从单个数据行创建饼图-SAS分析

从单个数据行创建饼图-SAS分析,sas,Sas,我有一个数据集,它包括一个产品变量、一个区域变量,然后是过去10年中的每一年作为一个单独变量,因此数据集总共有12个变量 我不知道如何将单行中的数据显示在饼图中 数据集看起来如此,只是为了更易于可视化: Product Area year1 year2 year3 1 1 7 14 7 1 2 12 15 11 1 3 5 9 8 2 1

我有一个数据集,它包括一个产品变量、一个区域变量,然后是过去10年中的每一年作为一个单独变量,因此数据集总共有12个变量

我不知道如何将单行中的数据显示在饼图中

数据集看起来如此,只是为了更易于可视化:

Product  Area  year1  year2  year3
  1       1     7      14      7  
  1       2     12     15      11
  1       3     5      9       8
  2       1     4      12      5
  2       2     8      3       14
  2       3     5      0       2
  3       1     2      12      12
我的最终结果是能够输入产品1和区域3,然后让它生成一个饼图,显示每年的值。我想不出一个办法,但是,我目前的知识和研究表明,从一排拉是不可能的

  • 首先使用proc转置将年份变量堆叠在一列中
  • 然后按产品区域制作一个带有
    的普通饼图
    为每一原始行创建一个图表(假设Product*Area实际上是您的行的唯一ID)。我在这里使用了
    proc gchart

    *** DEFINE DATA --------------;
    data have;
        infile datalines dlm=' ';
        input Product  Area  year1  year2  year3;
        datalines;
    1 1 7 14 7
    1 2 12 15 11
    1 3 5 9 8
    2 1 4 12 5
    2 2 8 3 14
    2 3 5 0 2
    3 1 2 12 12
    ;run;
    
    *** STACK YEARS --------------;
    proc sort data=work.have out=work.tmp0temptableinput;
        by product area;
        run;
    proc sql;
        create view work.tt1 as
        select src.*, "values" as _eg_idcol_
        from work.tmp0temptableinput as src;
        quit;
    proc transpose data=work.tt1
            out=work.tt2
            name=year;
        by product area;
        id _eg_idcol_;
        var year:; * THIS IS GENERALISED FOR FOR THAN 3 YEARxx VARIABLES;
        run;
    proc datasets lib=work nolist;
        modify tt2;
        label values = ;
        label year = ;
        label valuedescription = ;
        run;
    
    *** PLOT --------------;
    proc sort
        data=work.tt2
        out=work.tt3;
        by product area;
        run;
    proc gchart data =work.tt3;
        pie  year /
            sumvar=values
            type=sum
            nolegend
            slice=outside
            percent=none
            value=outside
            other=4
            otherlabel="other"
            coutline=black
            noheading
            ;
        by product area;
        run; quit;
    
  • 首先使用proc转置将年份变量堆叠在一列中
  • 然后按产品区域制作一个带有
    的普通饼图
    为每一原始行创建一个图表(假设Product*Area实际上是您的行的唯一ID)。我在这里使用了
    proc gchart

    *** DEFINE DATA --------------;
    data have;
        infile datalines dlm=' ';
        input Product  Area  year1  year2  year3;
        datalines;
    1 1 7 14 7
    1 2 12 15 11
    1 3 5 9 8
    2 1 4 12 5
    2 2 8 3 14
    2 3 5 0 2
    3 1 2 12 12
    ;run;
    
    *** STACK YEARS --------------;
    proc sort data=work.have out=work.tmp0temptableinput;
        by product area;
        run;
    proc sql;
        create view work.tt1 as
        select src.*, "values" as _eg_idcol_
        from work.tmp0temptableinput as src;
        quit;
    proc transpose data=work.tt1
            out=work.tt2
            name=year;
        by product area;
        id _eg_idcol_;
        var year:; * THIS IS GENERALISED FOR FOR THAN 3 YEARxx VARIABLES;
        run;
    proc datasets lib=work nolist;
        modify tt2;
        label values = ;
        label year = ;
        label valuedescription = ;
        run;
    
    *** PLOT --------------;
    proc sort
        data=work.tt2
        out=work.tt3;
        by product area;
        run;
    proc gchart data =work.tt3;
        pie  year /
            sumvar=values
            type=sum
            nolegend
            slice=outside
            percent=none
            value=outside
            other=4
            otherlabel="other"
            coutline=black
            noheading
            ;
        by product area;
        run; quit;
    

  • 谢谢,非常有帮助。谢谢,非常有帮助。