Date: Mon, 26 May 2008 07:03:05 -0400
Reply-To: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject: Re: Repeated recursive joins
In-Reply-To: <2fc7f3340805251729n754fd4bfxb90ccaa7a61e4aa3@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
To all,
On further thought about linking on both directions, here is an example data
set.
data dsn1;
input v1 $ v2 $;
datalines;
a1 a2
a3 a4
a6 a7
a8 a9
a10 End
a5 a6
a9 a10
a7 a8
a4 a5
a2 a3
;
run;
Here chain starts with a1 and ends in 'End' traveling in the course in
either directions giving a result of
a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 End
Two of the three programs posted find this result. The first program misses
the check of a terminal condition. Here is the code with that check.
data dsn1_vw/view=dsn1_vw;
retain closed ' ';
set dsn1;
run;
data need;
if _n_ = 1 then do;
set dsn1(keep = v1 v2);
declare hash h(dataset:'dsn1_vw');
h.definekey('v1');
h.definedata('v1','v2','closed');
h.definedone();
end;
num = h.Num_Items;
length chain $ 100;
do until(eof);
set dsn1 (keep = v1) end = eof;
rc = 0;
do k = 1 to num while(rc = 0);
rc = h.find();
if rc ne 0 or closed = 'y' then leave;
chain = catx(' ', chain, v1);
closed = 'y';
rc1 = h.replace();
v1 = v2;
end;
if rc ne 0 or closed ne 'y' or k > num then do; *** added the terminal
check ;
chain = catx(' ', chain, v1);
output;
end;
chain = ' ';
end;
stop;
keep chain;
run;
Muthia Kachirayan