data x;
input Code Year ML BL LTU;
cards;
/*数据区*/
;run;
/*设每组code需要删除的year数目定义为n,若源数据每组year数目不足n的则定义为删除整组*/
%let n=3;
proc sql noprint;create table x_new as select *,count(*)/4 as d
from x group by code having d>&n ;
select * from x_new order by code , year desc;
create table final as select * from x_new group by code
having min(year)+&n<=year<=max(year) order code ,year desc;quit;