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.
id | measure1 | measure2 | measure3 |
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 |
and I need the new data set like this.
id | measure1 | measure2 | measure3 |
1001 | 12 | 22 | 33 |
1002 | 12 | 20 | 23 |
1003 | 8 | 22 | 30 |
Thank you so much for your help in advance,
Bo
Update can do that easily. e.g.:
data want;
update have (obs=0) have;
by id;
run;
Update can do that easily. e.g.:
data want;
update have (obs=0) have;
by id;
run;
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;
Thank you Both Arthur and DBailey for your help...Bo
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.