Hi,
I need to write a SAS code to identify the year when salary changed as attachment. Any idea is appreciated. As you can see the building value in 2009 for A and 2011 for C have changed from 0 to something.
ID Year Salary
A 2007 0.00
A 2008 0.00
A 2009 100.00
A 2010 200.00
B 2009 500.00
B 2010 700.00
B 2011 300.00
B 2012 200.00
C 2010 0.00
C 2011 200.00
C 2012 400.00作者: shiyiming 时间: 2012-5-27 12:11 标题: Re: SAS程序去找到薪水变动从无到有的年份。 [code:2czw01oi]
data ads;
input ID $ Year Salary;
retain r 0;
if id^=lag(id) then r+1;
if (r=lag(r) & salary=dif(salary) & salary^=0) then a=1;
else a=0;
cards;
A 2007 0.00
A 2008 0.00
A 2009 100.00
A 2010 200.00
B 2009 500.00
B 2010 700.00
B 2011 300.00
B 2012 200.00
C 2010 0.00
C 2011 200.00
C 2012 400.00
;
data bds;
set ads;
if a;
drop r a;
run;
[/code:2czw01oi]作者: shiyiming 时间: 2012-5-29 11:43 标题: Re: SAS程序去找到薪水变动从无到有的年份。 [code:3qm7e8pz]
data ads;
input ID $ Year Salary;
cards;
A 2007 0.00
A 2008 0.00
A 2009 100.00
A 2010 200.00
B 2009 500.00
B 2010 700.00
B 2011 300.00
B 2012 200.00
C 2010 0.00
C 2011 200.00
C 2012 400.00
;
run;
proc means data=ads noprint nway;
class ID;
var Salary;
output out=_change idgroup(min(Year) out[1](Year Salary)=)/autoname;
where Salary>0;
run;
[/code:3qm7e8pz]