LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 20 May 2007 10:39:42 -0400
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: how to grab the Subsequent record(a better approach) ?
Comments: To: SAS_learner <proccontents@gmail.com>
In-Reply-To:  <c2192a610705200724y7fcf9b7br4930b2210d17675a@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Post some example data. And desired output.

On 5/20/07, SAS_learner <proccontents@gmail.com> wrote: > Hello all, > > After seeing Richard's macro on lag function I thought some body would > have a better Idea of doing this one > > What I was doing other day is not entirely a Lag but some thing (reverse) of > that kind . Here is what I wanted to accomplished other day > > "If there is a record where DOSEDT and PREDOSE are both non-,missing prior > to first dose date (that is, DOSEDT < FDDT), then for the last DOSEDT prior > to FDDT > CORTDUR = ( *DOSEDT (subsequent record)* - FDDT)" > > > For grabing the Subsequent record for a same patient I had to write this > way. I know it is pretty ineffient way but I could not think of better way. > Here is way I tried to achive it does anybody has better way of doing it. > > data aa_1 ; > set a_temp ; > by pt ; > if dosedt >= fddt then dosedt3 = dosedt ; > if dosedt >= fddt then cortdur_fir_rec = dosedt3 - fddt ; > if not first.pt then count = 1 ; > if count = 1 ; > keep pt cortdur_fir_rec ; > format dosedt3 date9. ; > run; > > data aa_2 ; > set aa_1 ; > by pt ; > if /*first.pt and */ cortdur_fir_rec = . then delete ; > run; > > data aa_2 ; > set aa_2 ; > by pt ; > if first.pt ; > run; > data aa_l1 ; > set a_temp ; > by pt ; > if dosedt < fddt ; > run; > > data aa_l1 ; > set aa_l1 ; > by pt ; > if last.pt ; > run; > > proc sort data = aa_l1 ; > by pt ; > run; > > data aa_2 ; > merge aa_2 aa_l1 ; > by pt ; > if cortdur= . then cortdur = cortdur_fir_rec ; > run; > > proc sort data = aa_2 ; > by pt dosedt ; > run; > > proc sort data = a_temp ; > by pt dosedt ; > run; > > data a_temp ; > merge a_temp(In= a) aa_2 ; > by pt dosedt ; > retain cortdur ; > if a ; > if cortdur= . then cortdur = cortdur_fir_rec ; > if first.pt and dosedt = . then cortdur = .; > drop cortdur_fir_rec; > run; > > proc sort data = v_predose ; > by pt dosedt ; > run; > > proc sort data = a_temp nodupkey ; > by pt dosedt ; > run; > > data v_cortdur; > merge v_predose (in = a ) > a_temp (keep = pt cortdur dosedt) > ; > by pt dosedt ; > if a ; > run; > > proc sort data = v_cortdur ; > by pt dosedt ; > run; > > thanks for advice . >


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