LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 24 Nov 2003 17:46:47 +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
Comments: To: Richard Read Allen <peakstat@WISPERTEL.NET>
In-Reply-To:  <E1AOL9M-0003ja-00@coumxnn01.netbenefit.co.uk>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 11:09 24/11/03 -0700, Richard Read Allen wrote:

>Helen, Below is a simple way to accomplish what you want using retain >rather than lag. One caution about the lag function is that it's best not >to use it in >a conditional statement as you have done (twice). It does funky things when >used this way. > >[snip] > >data two; > set one; > retain x; > if y>. then x=y; >run;

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 ;

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 ----------------------------------------------------------------


Back to: Top of message | Previous page | Main SAS-L page