```Date: Fri, 30 Jul 2004 11:17:14 -0400 Reply-To: Venky Chakravarthy Sender: "SAS(r) Discussion" From: Venky Chakravarthy Subject: Re: data step Comments: To: Hua Gang On Thu, 29 Jul 2004 15:02:43 -0700, hua gang wrote: > id t0 t1 t2 t3 x0 x1 > x2 x3 X > > 1 0 0 0 1 2 > 3 0 5 . > 2 0 0 0 0 5 > 3 4 5 . > 3 0 . 1 0 9 > . 7 1 1 > 4 0 0 1 0 8 > 0 1 3 3 > 5 0 1 0 0 7 > 7 . 0 . > 6 1 1 1 1 5 > 1 6 2 1 > 7 . 0 . . 3 > 1 2 . . > 8 1 1 1 . 0 > 2 . 3 2 > 9 0 1 . . 0 > 6 4 . 4 > > >In above data, I have 2 sets of time-varying >variable: t0 - t3, and x0 - x3. I want to >create a new variable, X by getting value from x0 - >x3, >conditional on t0 - t3. > >rules: >1. value of X should be taken from x0-x3 at the > time point following t0 - t3 = 1. E.g., X = 3 for >id #4, > & X = 4 for ID #9. > >2. If t0-t3 never had 1, or t3=1 (no follow-up data >after t3=1), >value of X should = missing. E.g., X=. for id #1, #2, >etc. > >Thanx, > >Gang > > > >__________________________________ >Do you Yahoo!? >New and Improved Yahoo! Mail - Send 10MB messages! >http://promotions.yahoo.com/new_mail What is the rule for id #6? It has no follow-up but has t0-t2. Is the value of x really 1 as in your example or is it missing? Assuming that your example is what you really want, I think the problem statement is simplified. You need to only look at values from t0-t2 and if any of that is 1 then take the next time point value from x1-x3 to populate X. Otherwise, you do nothing and X does not get initialized, thus remains a missing value. About the solution (below my sig), I have become a fan of the Dorfman Bodiless Loop. If more people start using it, this might need an acronym (DBL) :-). Venky Chakravarthy data q ; input id t0 t1 t2 t3 x0 x1 x2 x3 ; cards; 1 0 0 0 1 2 3 0 5 2 0 0 0 0 5 3 4 5 3 0 . 1 0 9 . 7 1 4 0 0 1 0 8 0 1 3 5 0 1 0 0 7 7 . 0 6 1 1 1 1 5 1 6 2 7 . 0 . . 3 1 2 . 8 1 1 1 . 0 2 . 3 9 0 1 . . 0 6 4 . run ; data w (drop=_:) ; set q ; array _t (*) t0 - t3 ; array _x (*) x0 - x3 ; do _i = 1 to dim(_t) until(_t(_i)) ; end ; if _i<4 then x = _x(_i+1) ; run ; options nocenter ; proc print ; run ; Obs ID T0 T1 T2 T3 X0 X1 X2 X3 X 1 1 0 0 0 1 2 3 0 5 . 2 2 0 0 0 0 5 3 4 5 . 3 3 0 . 1 0 9 . 7 1 1 4 4 0 0 1 0 8 0 1 3 3 5 5 0 1 0 0 7 7 . 0 . 6 6 1 1 1 1 5 1 6 2 1 7 7 . 0 . . 3 1 2 . . 8 8 1 1 1 . 0 2 . 3 2 9 9 0 1 . . 0 6 4 . 4 ```

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