BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASleaner
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Update can do that easily.  e.g.:

data want;

  update have (obs=0) have;

  by id;

run;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

Update can do that easily.  e.g.:

data want;

  update have (obs=0) have;

  by id;

run;

DBailey
Lapis Lazuli | Level 10

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;

SASleaner
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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