proc sort data=test5;by stkcd descending year;run;
data test6;set test5;by stkcd;
retain m n o p q;
if not (first.stkcd) then soe=coalesce(soe,m);
if not (first.stkcd) then central_soe=coalesce(central_soe,n);
if not (first.stkcd) then provincial_soe=coalesce(provincial_soe,o);
if not (first.stkcd) then city_below_soe=coalesce(city_below_soe,p);
if not (first.stkcd) then other_soe=coalesce(other_soe,q);
m=soe;
n=central_soe;
o=provincial_soe;
p=city_below_soe;
q=other_soe;
drop m n o p q;
run;