And yet another hash variation.
data want(drop=_: rename=(cust_id=Expected_cust_id p_cust_id=cust_id));
if _n_=1 then
do;
dcl hash h1(dataset:'have(where=(not missing(p_cust_id)))' );
h1.defineKey('p_cust_id');
h1.defineData('cust_id');
h1.defineDone();
end;
set have(where=(not missing(p_cust_id)));
output;
/* lookup children, counter loop added to avoid endless loops in case of DQ issues */
do _i=1 to 10000 while(h1.find(key:cust_id)=0);
output;
end;
if _i>=10000 then
do;
putlog "DQ issues found leading to endless loop";
putlog "Source record is: " _n_ 10. -l;
end;
run;