data test01;
set test;
by id year;
preyear=lag(year);
if not first.id then do;
dif=year-preyear;
if dif ne 1 then output;
end;
run;
proc sql;
create table test02 as
select *
from test
where cats(put(id,best.), put(year, best.)) in (select cats(put(id,best.), put(year, best.)) from test01)
or cats(put(id,best.), put(year, best.)) in (select cats(put(id,best.), put(preyear, best.)) from test01);
quit;
data test01;
set test;
by id year;
preyear=lag(year);
if not first.id then do;
dif=year-preyear;
if dif ne 1 then output;
end;
run;
proc sql;
create table test02 as
select *
from test
where cats(put(id,best.), put(year, best.)) in (select cats(put(id,best.), put(year, best.)) from test01)
or cats(put(id,best.), put(year, best.)) in (select cats(put(id,best.), put(preyear, best.)) from test01);
quit;