You can also make use of the subGraphs macro given here, this way :
data have;
infile datalines dlm="-";
length id1 id2 $7;
input (id1 id2) (:$7.);
datalines;
123-456
111-222
111-333
222-333
333-444
333-555
666-777
444-888
444-555
888-777
123-987
654-321
;
%include "&sasforum\subGraphsMacro.sas";
%SubGraphs(have,from=id1,to=id2,out=groups);
proc sort data=groups; by clust node; run;
data chains;
length chain $100;
chain_ID + 1;
do until(last.clust);
set groups; by clust;
chain = catx("-", chain, node);
end;
keep chain_ID chain;
run;
proc print data=chains noobs; run;
chain chain_ID
123-456-987 1
111-222-333-444-555-666-777-888 2
321-654 3
... View more