在SAS中创建新的总和和百分比列

时间:2019-05-14 00:06:20

标签: sas

我有以下数据集:

con.setAutoCommit(false);

我想在SAS中为每个位置创建三个额外的列:雇员总数,警察百分比和消防员百分比。更新的数据集应如下所示:

Locations      Occupation
001            Teacher
001            Fireman
002            Teacher
002            Policeman
002            Fireman
003            Teacher
003            Teacher
003            Fireman
003            Policeman

谢谢!

1 个答案:

答案 0 :(得分:0)

只需使用sql即可获得摘要统计信息,然后与原始数据合并:

proc sql;
create table summary as 
select locations, count(*) as totalemployed, 
    sum(occupation='Policeman')/calculated totalemployed as percentpolice,
    sum(occupation='Fireman')/calculated totalemployed as percentfireman

from chk1
group by locations;
quit;

data final;
merge chk1 summary;
by locations;
run;

enter image description here