pf! Using hash searching is absolutely right solution to sovle this sort of problem!
[quote="hopewell":znd11mcn][code:znd11mcn]data regular;
set sample;
rename child=c parent=highest_parent;
run;
data out(drop=rc c);
length c highest_parent $8;
if _n_=1 then do;
declare hash h(dataset:'regular');
rc=h.defineKey('c');
rc=h.defineData('highest_parent');
rc=h.defineDone();
call missing(c,highest_parent);
end;
set sample;
highest_parent=parent;
do while(h.find(key:highest_parent)=0);
end;
run;[/code:znd11mcn][/quote:znd11mcn]
[quote="hopewell":2rw35q2y][code:2rw35q2y]data regular;
set sample;
rename child=c parent=highest_parent;
run;
data out(drop=rc c);
length c highest_parent $8;
if _n_=1 then do;
declare hash h(dataset:'regular');
rc=h.defineKey('c');
rc=h.defineData('highest_parent');
rc=h.defineDone();
call missing(c,highest_parent);
end;
set sample;
highest_parent=parent;
do while(h.find(key:highest_parent)=0);
end;
run;[/code:2rw35q2y][/quote:2rw35q2y]