2017-06-22 115 views
0

的比例,我有以下PROC報告PROC報告:組和

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

sashelp class

但是我不想顯示重量的總和。相反,我想有分組總和的比例。所以第一排應該是6.23%。我怎樣才能做到這一點?

回答

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一步一個解決方案...