1

我正在使用 proc 方法来计算业务线支付的份额,数据如下所示:

data Test;
input ID Business_Line Payment2017;
Datalines;
1 1 1000
2 1 2000
3 1 3000
4 1 4000
5 2 500
6 2 1500
7 2 3000
;
run;

我正在计算一个附加列,该列按组(business_line)计算付款的百分比(权重),如下所示:

   data Test;
input ID Business_Line Payment2017 share;
Datalines;
1 1 1000 0.1
2 1 2000 0.2
3 1 3000 0.3
4 1 4000 0.4
5 2 500 0.1
6 2 1500 0.3
7 2 3000 0.6
;
run;

到目前为止我使用的代码:

proc means data = test noprint;
class ID;
by business_line;
var Payment2017;
output out=test2 
sum = share;
weight = payment2017/share;
run;

我也试过

proc means data = test noprint;
class ID;
by business_line;
var Payment2017 /weight = payment2017;
output out=test3 ;
run;

感谢帮助。

4

2 回答 2

3

Proc FREQ将计算百分比。您可以划分PERCENT输出的列以获得分数,或使用下游的百分比。

在此示例中,id交叉payment2017以确保所有原始行都是输出的一部分。如果id不存在,并且有任何重复支付金额,FREQ则将汇总支付金额。

proc freq data=have noprint;
 by business_line;
 table id*payment2017 / out=want all;
 weight payment2017 ;
run;
于 2018-03-29T14:17:17.957 回答
1

用proc sql做起来很方便:

proc sql;
   select *, payment2017/sum(payment2017) as share from test group by business_line;
quit;

数据步骤:

data have;
    do until (last.business_line);
    set test;
    by business_line notsorted;
    total+payment2017;
    end;
    do until (last.business_line);
    set test;
    by business_line notsorted;
    share=payment2017/total;
    output;
    end;
    call missing(total);
    drop total;
run;
于 2018-03-29T13:35:11.027 回答