我的办法很笨,如下;
proc sql;
create table test1 as
select a.*, b.com1 as lastYcom1, b.com2 as lastYcom2, b.com3 as lastYcom3
from sample as a left join sample as b
on a.id=b.id and a.year=b.year+1
order by id year;
quit;
data test1; set test1;
if lastYcom1 ne . then do;
if com1=lastYcom1 then com1ChangeY1=0;
else com1changeY1=1;
if com1=lastYcom1 or com1=lastYcom2 or com1=lastYcom3 then com1changein3com_Y1=1;
else com1changein3com_Y1=0;
end;
run;