0

我有以下过程报告

proc report data=sashelp.class;
  col
    sex
    age
    weight
  ;
  define sex / group;
  define age / group;
  define weight / analysis sum;
run;

sashelp 类

但是我不想显示重量的总和。相反,我想要分组总和的比例。所以第一行应该是 6.23%。我怎样才能做到这一点?

4

1 回答 1

0

现在我找到了一种解决方法:

proc sql noprint;
CREATE TABLE class AS
SELECT a.*
    ,b.sumweight
FROM sashelp.class a
LEFT JOIN (SELECT sex, sum(weight) as sumweight
            FROM sashelp.class
            GROUP BY sex
) b
ON a.sex=b.sex
;
quit;

proc report data=class;
col
    sex
    age
    weight
    sumweight
    perc
;
define sex / group;
define age / group;
define weight / analysis sum;
define sumweight / analysis mean noprint;
define perc / computed format=percent6.2;

compute perc;
    perc = weight.sum/sumweight.mean;
endcomp;
run;

但也许有一个没有额外的proc sql步骤的解决方案......

于 2017-06-22T08:28:36.660 回答