t**i 发帖数: 387 | 1 【 以下文字转载自 Statistics 讨论区 】
发信人: toni (toni), 信区: Statistics
标 题: 一个SAS sql的问题
发信站: BBS 未名空间站 (Mon Dec 30 16:18:39 2013, 美东)
刚接触SAS sql,有个问题求教:
现有2各表employees和bonus
employees表有列name, department, base_salary
bonus表有列year, department, bonus
现要用sql实现:返回employees表中所有的obs,用employees表中的department和year(
2012,2013)查询bonus表的bonus,给employees加上2列salary2012, salary2013
以下是我现有的一些code(不能同时返回2012和2013的total salary)
data employees;
input name $ dep $ base_salary;
datalines;
Charles Sales 70000
James HR 80000
Cindy HR 75000
Steven Sales 80000
;
data bonus;
input year dep $ bonus;
datalines;
2012 Sales 10000
2012 Marketing 12000
2012 HR 8000
2013 Sales 18000
2013 Marketing 20000
2013 HR 16000
;
proc sql;
select a.name, a.dep, a.base_salary, a.base_salary+b.bonus as salary2013
from employees a, bonus b where a.dep = b.dep and b.year=2013;
quit; | s******o 发帖数: 656 | 2 一个笨办法:
proc sql;
create table sa2013 as
select a.name, a.dep, a.base_salary, a.base_salary+b.bonus as salary2013
from employees a, bonus b
where a.dep = b.dep and b.year=2013;
create table sa2012 as
select a.name, a.dep, a.base_salary+b.bonus as salary2012
from employees a, bonus b
where a.dep = b.dep and b.year=2012;
create table salary as
select c.*, d.salary2012
from sa2013 c, sa2012 d
where c.name=d.name and c.dep=d.dep;
quit;
【在 t**i 的大作中提到】 : 【 以下文字转载自 Statistics 讨论区 】 : 发信人: toni (toni), 信区: Statistics : 标 题: 一个SAS sql的问题 : 发信站: BBS 未名空间站 (Mon Dec 30 16:18:39 2013, 美东) : 刚接触SAS sql,有个问题求教: : 现有2各表employees和bonus : employees表有列name, department, base_salary : bonus表有列year, department, bonus : 现要用sql实现:返回employees表中所有的obs,用employees表中的department和year( : 2012,2013)查询bonus表的bonus,给employees加上2列salary2012, salary2013
|
|