data t2;
length var $ 400;
retain var ;
set tmp end=last;
by year;
if first.year then sum=0;
sum+1;
if last.year then do;
if sum<7 then var=catx(',',compress(var),compress(year));
end;
if last then call symput('varname',var) ;
run;
data t3(drop=var sum);
set t2;
if year in(&varname) then delete;
run;
data tmp;
input year $ x;
datalines;
1997 1
1997 2
1998 1
1998 2
1998 3
1998 4
1998 5
1998 6
1998 7
1998 8
1999 1
1999 2
;
run;
proc sql;create table final as select * from tmp group by year having count((year))>=7 order year ,x ;quit;