Prev: HASH HELP NEEDED
Next: How to test median
From: sas analysis on 19 Apr 2010 21:11 Hi all, I have the following longitudinal data: ID event 1 0 1 0 1 0 1 1 1 0 1 0 1 0 How can I assign observations as missing after the event hits 1. This is how I want the data to look: ID event 1 0 1 0 1 0 1 1 1 . 1 . 1 . any help would be much appreciated! Thanks!
From: Reeza on 19 Apr 2010 21:17 On Apr 19, 6:11 pm, sas analysis <sasanaly...(a)gmail.com> wrote: > Hi all, > > I have the following longitudinal data: > > ID event > 1 0 > 1 0 > 1 0 > 1 1 > 1 0 > 1 0 > 1 0 > > How can I assign observations as missing after the event hits 1. > > This is how I want the data to look: > > ID event > 1 0 > 1 0 > 1 0 > 1 1 > 1 . > 1 . > 1 . > > any help would be much appreciated! > > Thanks! Use the retain statement and a flag.. proc sort data=have; by id; data want; set have; by id; retain flag 0; if first.id then flag=0; *reset variable for each id; if flag=0 and event=1 then flag=1; if event=0 and flag=1 then event=.; if event=1 and flag=1 then event=.; *my assumption, you can change to what you want; run; HTH, Reeza
From: sas analysis on 19 Apr 2010 21:29 On Apr 19, 8:17 pm, Reeza <fkhurs...(a)hotmail.com> wrote: > On Apr 19, 6:11 pm, sas analysis <sasanaly...(a)gmail.com> wrote: > > > > > > > Hi all, > > > I have the following longitudinal data: > > > ID event > > 1 0 > > 1 0 > > 1 0 > > 1 1 > > 1 0 > > 1 0 > > 1 0 > > > How can I assign observations as missing after the event hits 1. > > > This is how I want the data to look: > > > ID event > > 1 0 > > 1 0 > > 1 0 > > 1 1 > > 1 . > > 1 . > > 1 . > > > any help would be much appreciated! > > > Thanks! > > Use the retain statement and a flag.. > > proc sort data=have; by id; > > data want; > set have; > by id; > retain flag 0; > if first.id then flag=0; *reset variable for each id; > if flag=0 and event=1 then flag=1; > if event=0 and flag=1 then event=.; > if event=1 and flag=1 then event=.; *my assumption, you can change to > what you want; > run; > > HTH, > Reeza- Hide quoted text - > > - Show quoted text - Hi Reeza, Thank you very much. I tried this code but it is actually deleting the event=1 too. Is there a way to delete right after the event hits a 1? thanks much!
From: Reeza on 19 Apr 2010 21:48 On Apr 19, 6:29 pm, sas analysis <sasanaly...(a)gmail.com> wrote: > On Apr 19, 8:17 pm, Reeza <fkhurs...(a)hotmail.com> wrote: > > > > > > > On Apr 19, 6:11 pm, sas analysis <sasanaly...(a)gmail.com> wrote: > > > > Hi all, > > > > I have the following longitudinal data: > > > > ID event > > > 1 0 > > > 1 0 > > > 1 0 > > > 1 1 > > > 1 0 > > > 1 0 > > > 1 0 > > > > How can I assign observations as missing after the event hits 1. > > > > This is how I want the data to look: > > > > ID event > > > 1 0 > > > 1 0 > > > 1 0 > > > 1 1 > > > 1 . > > > 1 . > > > 1 . > > > > any help would be much appreciated! > > > > Thanks! > > > Use the retain statement and a flag.. > > > proc sort data=have; by id; > > > data want; > > set have; > > by id; > > retain flag 0; > > if first.id then flag=0; *reset variable for each id; > > if flag=0 and event=1 then flag=1; > > if event=0 and flag=1 then event=.; > > if event=1 and flag=1 then event=.; *my assumption, you can change to > > what you want; > > run; > > > HTH, > > Reeza- Hide quoted text - > > > - Show quoted text - > > Hi Reeza, > > Thank you very much. I tried this code but it is actually deleting the > event=1 too. > Is there a way to delete right after the event hits a 1? > > thanks much! My bad...its operating in the order of the if then statements set out above...so if the event=1 and flag =1 which it gets set too, it gets reset to missing. Change the orders to get what you need. :)
|
Pages: 1 Prev: HASH HELP NEEDED Next: How to test median |