proc sql outobs=20;
title ’Job Groups with Average Salary’;
title2 ’> Company Average’;
select jobcode,
avg(salary) as AvgSalary format=dollar11.2,
count(*) as Count
from sasuser.payrollmaster
group by jobcode
having avg(salary) >
(select avg(salary)
from sasuser.payrollmaster)
order by avgsalary desc;
这个里面主要是注意一点:
就是HAVING语句中的AVG(salary)比较是全部数据中的薪水的平均值,而AVG(SALARY)是按照分组计算出来的薪水的平均值,这里将select avg(salary)
from sasuser.payrollmaster的结果做比较的对象。