Date: Thu, 15 Sep 2005 14:12:13 -0400
Reply-To: Talbot Michael Katz <topkatz@MSN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Talbot Michael Katz <topkatz@MSN.COM>
Subject: Re: help on translating Talbot Michael Katz's "discontinue a test
code"
Hi, Mimi.
You've already seen the response I sent you privately, but I'll post it
here, too.
data tdm2 ;
set tdm1 ;
array bds{*} bds: ; * group into array for
looping ;
drop i triple ; * just for use in data
step ;
triple = 0 ; * initialize flag to tell
when triple has been found ;
do i = lbound(bds) to hbound
(bds) ; * loop through entire array for each
record ;
if triple < 3 then triple =
(triple + 1) * (bds{i} = 0) ; *
this is where
all the work is being done. if you have not hit a triple yet, every time
you see a zero, increment the triple counter. if you see a one before the
triple counter gets to three, the triple counter gets reset to zero ;
else bds{i} = 0 ; * triple has
been hit, so set all remaining to 0 ;
end ;
run ;
As I remarked to you, both Cassell and Chakravarthy offered better
solutions, which turn out to be more easily adaptible to other discontinue
criteria, such as three zeroes out of four:
data tdm3 ;
set tdm1 ;
array bds{*} bds: ; * group into array for
looping ;
drop i j hbm2 hbp1 lbp1 ; *
just for use in data step ;
hbm2 = hbound(bds) - 2 ; *
highest index to loop through ;
hbp1 = hbound(bds) + 1 ; * one
past the last index ;
lbp1 = lbound(bds) + 1 ; *
lowest index to loop through ;
do i = lbp1 to hbm2 while (sum(bds
{i},bds{i+1},bds{i+2},bds{i-1}) > 1) ; * tight
loop until reach end or violate rule ;
end ;
do j = (((i le hbm2) * i)
+ ((i > hbm2) * hbp1)) to hbound
(bds) ; * if rule
violated, loop until end of array, setting to zero. otherwise, set lower
bound past upper bound to avoid looping ;
bds{j} = 0 ;
end ;
run ;
Good luck!
-- TMK --
"The Macro Klutz"
On Thu, 15 Sep 2005 12:30:43 -0500, mimi <meng4sas@GMAIL.COM> wrote:
>Hi, Everyone,
>especially Talbot :-)
> would you please help me on explaning the code that Talbot suggested on
how
>to discontinue a test.
> Here is the situation.
>I want to score all the items to 0s after 3 consecutive 0 occurs.
>here is the fake data:
>*
>
>data tdm1;
>
>input teid age @7 (bd01-bd20)(1.);
>
>cards;
>
>110 6 00011100011000010110
>
>111 7 00100011000000000000
>
>;
>
>*here is what Talbot suggested.
>*
>
>data* tdm2 ; set tdm1;
>
>array bds{*} bds: ;
>
>drop i triple ;
>
>triple = *0* ;
>
>do i = lbound(bds) to hbound(bds) ;
>
>if triple < *3* then triple =(triple + *1*) * (bds{i} = *0*) ;
>
>else bds{i} = *0* ;
>
>end ;
>
>*
>
>run* ;
>
> but I don't really understand the logic here.
>
>can anyone explan line by line for me?
>
>Thanks.
>
> Mimi
|