Date: Mon, 24 Nov 2003 18:14:10 +0000
Reply-To: John Whittington <John.W@MEDISCIENCE.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Whittington <John.W@MEDISCIENCE.CO.UK>
Subject: Re: how to use lag
Content-Type: text/plain; charset="us-ascii"; format=flowed
Whoops. I recently wrote:
>Richard, I'm afraid there are all sorts of reasons why this code would not
>accomplish what Helen wants.
>
>Firstly, it does not respect the ID boundaries, as Helen wants - i.e. it
>would attempt to 'carry forward' data from one ID to the next. Secondly,
>the logic of the code is simply not correct. As written, the value of x
>will ALWAYS be missing, and will not achieve the desired 'carry
>forward'. However, it is very easy to achieve Helen's desired
>functionality using RETAIN rather than lag functions, something like:
>
>data two (drop = last_y) ;
> retain last_y ;
> set one;
> by id;
> if first.id then x=y;
> else if y=. then x=last_y;
> else x=y;
> last_y = y ;
>run ;
I had misread Richard's "if y>." as being "if y=.", hence my statement
about x always having a missing value is incorrect. However, I still stand
by the rest of what I said, and the suggested code (as above).
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------
|