[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Picking a value from one variable based on values in another
From:       Muthia Kachirayan <muthia.kachirayan () GMAIL ! COM>
Date:       2010-02-26 21:05:00
Message-ID: 2fc7f3341002261305g6686943ob0e5c9b237785eff () mail ! gmail ! com
[Download RAW message or body]

How about a double DoW-loop ?


data sample;
   input Student time var $char1.;
cards;
1 1 M
1 2 0
1 3 0
1 4 1
1 5 1
2 1 0
2 2 0
2 3 0
3 2 M
3 3 1
4 2 0
4 4 1
4 5 1
;
run;

data need;
do until(last.student);
   set sample;
   by student;
   if var = '0' then last0 = max(last0, time);
   else if var = '1' then first1 = min(first1, time);
end;
do until(last.student);
   set sample;
   by student;
   output;
end;
run;

proc print data = need;
run;


On Fri, Feb 26, 2010 at 4:21 PM, NorCalAngel <norcalangel@gmail.com> wrote:

> SOLVED! Thanks Mark!
>
>
> On Feb 26, 11:16 am, NorCalAngel <norcalan...@gmail.com> wrote:
> > Hello,
> >
> > I am working on a survival analysis and needing some help with the
> > initial data management. I'm trying to create a time in study, and a
> > time of event.
> >
> > My data is set up in such a manner:
> >
> > Student   time   var
> > 1       1       M
> > 1       2       0
> > 1       3       0
> > 1       4       1
> > 1       5       1
> > 2       1       0
> > 2       2       0
> > 2       3       0
> > 3       2       M
> > 3       3       1
> > 4       2       0
> > 4       4       1
> > 4       5       1
> >
> > What I would like to do, is to generate a variable that holds the time
> > in which the student last reported var=0, and separately, first
> > reported var=1.
> > Something like: last0 = max(time) where var=0 , and first1 = min(time)
> > where var=1
> >
> > I also need the time in which they first entered the study.
> >
> > I plan on creating time of event as the midpoint between first1 and
> > last0. Then the time in study/time to event would be time of event -
> > time at entry.
> >
> > Any suggestions?
> >
> > Thanks!
> > -Angel
>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic