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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.