From: sas analysis on
Hi all,

I have data that looks like this:

Id visit outcome
1 1 0
1 2 0
1 3 0
1 4 1
1 5 .
1 6 .
2 1 0
2 2 0
2 3 .
2 4 .


how can I get the last read observations given that the ones after are
missing for each subject.

so the data I need should look like this:

ID visit outcome
1 4 1
2 2 0

any ideas would be great?

I tried the following:
data want;
set have;
if last.id and outcome ne . then x=outcome;
run;

Thanks!
From: Reeza on
On Apr 20, 9:02 am, sas analysis <sasanaly...(a)gmail.com> wrote:
> Hi all,
>
> I have data that looks like this:
>
> Id    visit      outcome
> 1      1             0
> 1      2             0
> 1      3             0
> 1      4             1
> 1      5             .
> 1      6             .
> 2      1             0
> 2      2             0
> 2      3             .
> 2      4             .
>
> how can I get the last read observations given that the ones after are
> missing for each subject.
>
> so the data I need should look like this:
>
> ID    visit     outcome
> 1       4           1
> 2       2           0
>
> any ideas would be great?
>
> I tried the following:
> data want;
> set have;
> if last.id and outcome ne . then x=outcome;
> run;
>
> Thanks!

Use something similar to what I provided last time, but with an
'output' statement.

See the following for help with what you seem to be trying to do.

Good luck.

http://www2.sas.com/proceedings/sugi31/246-31.pdf
From: PJ on
Another option -

data test;
input id visit outcome;
cards;
1 1 0
1 2 0
1 3 0
1 4 1
1 5 .
1 6 .
2 1 0
2 2 0
2 3 .
2 4 .

;



data tt;
merge test test(firstobs=2 keep=outcome rename=outcome = out1);
run;

data tt1(drop=out1);
set tt;
by id out1 notsorted;
if first.out1 and out1 = . then output;
run;
From: shiva on
Hi,

Try this...hope this helps..

proc sort data=one;
by id;run;
data two;
set one(where=( outcome ne .));
by id;
if last.id then output;
run;

Thanks,
-Shiva


From: ajs2004 on
Same approach as Shiva's answer:

data a1;
input id visit outcome;
datalines;
1 1 0
1 2 0
1 3 0
1 4 1
1 5 .
1 6 .
2 1 0
2 2 0
2 3 .
2 4 .
;


data a2;
set a1 (where=(not missing(outcome)));
by id visit; /* Assumes data already sorted */
if last.id;
run;

proc print data=a2;
run;


What would you want if, say, outcome was missing at visit 2 but not
missing at visit 3?


On Apr 20, 5:02 pm, sas analysis <sasanaly...(a)gmail.com> wrote:
> Hi all,
>
> I have data that looks like this:
>
> Id    visit      outcome
> 1      1             0
> 1      2             0
> 1      3             0
> 1      4             1
> 1      5             .
> 1      6             .
> 2      1             0
> 2      2             0
> 2      3             .
> 2      4             .
>
> how can I get the last read observations given that the ones after are
> missing for each subject.
>
> so the data I need should look like this:
>
> ID    visit     outcome
> 1       4           1
> 2       2           0
>
> any ideas would be great?
>
> I tried the following:
> data want;
> set have;
> if last.id and outcome ne . then x=outcome;
> run;
>
> Thanks!