How to get missing data from row above?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to get missing data from row above?

I have a data set the subjects had several records of measurements. I would like to generate a data set that keep the last records of each subjects, however if the last one if missing then take the one above.  Here is what my raw data set looks like.

idmeasure1measure2measure3
1001102232
10011133
100112
1002943
10022033
10021223
10032230
100382230
100330

and I need the new data set like this.

idmeasure1measure2measure3
1001122233
1002122023
100382230

Thank you so much for your help in advance,

Bo


Accepted Solutions
Solution
‎01-31-2013 02:30 PM
PROC Star
Posts: 7,467

Re: How to get missing data from row above?

Posted in reply to SASleaner

Update can do that easily.  e.g.:

data want;

  update have (obs=0) have;

  by id;

run;

View solution in original post


All Replies
Solution
‎01-31-2013 02:30 PM
PROC Star
Posts: 7,467

Re: How to get missing data from row above?

Posted in reply to SASleaner

Update can do that easily.  e.g.:

data want;

  update have (obs=0) have;

  by id;

run;

Super Contributor
Posts: 578

Re: How to get missing data from row above?

Posted in reply to SASleaner

sort of a brute force method...but..seems to work..

data have;

input id measure1 measure2 measure3;

cards;

1001 10 22 32

1001 11 . 33

1001 12 . .

1002 9 . 43

1002 . 20 33

1002 12 . 23

1003 . 22 30

1003 8 22 30

1003 . . 30

run;

data want(drop=m1 m2 m3);

set have;

by id;

retain m1 . m2 . m3 .;

if measure1=. then measure1=m1;

else m1=measure1;

if measure2=. then measure2=m2;

else m2=measure2;

if measure3=. then measure3=m3;

else m3=measure3;

run;

Occasional Contributor
Posts: 5

Re: How to get missing data from row above?

Thank you Both Arthur and DBailey for your help...Bo

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 267 views
  • 3 likes
  • 3 in conversation