Date: Wed, 8 Dec 1999 16:02:10 GMT
Reply-To: California Doll <vwilkins@MY-DEJA.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: California Doll <vwilkins@MY-DEJA.COM>
Organization: Deja.com - Before you buy.
Subject: Re: a cumbersome situation with data manipulation
2 methods come into mind. I will post both since I do not know what
other processing is occuring in your program.
1) You can sort by 'test' in descending order (z y x) and take the next
record after test=d
2) You can use the LAG function to hold the last value then when test=d
you look at what was in the previous record.
Which method you use may depend on what other processing is occuring in
your data step.
--
California Doll
Today is the best preparation we have for what tomorrow may bring.
In article <82ltqv$9sp$1@nnrp1.deja.com>,
diltilia@my-deja.com wrote:
> Here's the situation:
>
> data a;
> input obs id test sequence answer $;
> cards;
> 1 1 11 0 a
> 2 1 11 1 b
> 3 1 11 2 c
> 4 1 11 3 d
> 5 1 12 0 a
> 6 1 12 1 b
> 7 2 21 0 b
> 8 2 21 1 d
> 9 3 31 0 a
> 10 3 31 1 c
> 11 3 31 2 d
> 12 3 31 3 b
> 13 3 31 4 d
> 14 3 32 0 d
> ;
>
> What I need to do here is: within each 'test' for each user,select the
> records where the answer is the one right before answer 'd'. In
another
> word, select the records which the sequence number is 1 less than the
> sequence number for answer 'd'.
>
> For example, for id '1' test '11', I want to select observation 3,
> for id '2' test '21', I want to select obs 7, and so on.
>
> What I did was to calculate a number 'newseq'(which equals 'obs'-1)
for
> each occurence where answer ='d', and take all these numbers into a
data
> set, then use sql to select * from the original data set where "obs"
> number is equal to this new variable 'newseq'. It does the job, but
not
> so efficient. Also, if I want to extend this logic: Let's say, if I
find
> out 'c' occurs most often before the answer 'd', and i want to select
> the records that's one step before 'c'...
>
> I'm suspecting that there's a simpler way to do this.
>
> Thanks in advance for your patience of reading through this question.
>
> -Diltilia
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
|