BookmarkSubscribeRSS Feed
keherder
Obsidian | Level 7

Hello! 

 

Wondering if anyone could help me with this. Here is a photo of my data set: 

Screen Shot 2021-12-09 at 10.36.46 PM.png

We are assuming that the heights stay the same for each visit. What I would like to do is fill in the missing height values with the value for visit 1 for the rest of the visits for each participant. For example, the height of participant 1484 was 196 at visit 1. I would like to replace the missing values for visits 2-6 with 196 for this participant and do the same for all participants. Does anyone know how I can code this?

 

Thank you so much!

4 REPLIES 4
japelin
Rhodochrosite | Level 12

You can use retain statements to achieve this, but if you need specific code, please provide the data in a usable form, not as an image.

Maybe the code is something like this. (I haven't tested it because I don't have the data)

 

data want;
  set biosd.lab_wide;
  by caseid;
  retain height;
  if first.caseid then height=height_cm_;
  else height_cm_=height;
  drop height;
run;
andreas_lds
Jade | Level 19

Imho the else-part needs an update:

else do;
  if missing(height_cm_) then do;
    height_cm_ = height;
  end;
end;

or shorter

else do;
  height_cm_ = coalesce(height_cm_, height);
end;
ballardw
Super User

What if the first visit does not have a measurement?

Have you verified that none of your Caseids have more than one measurement that is not unique? Children over a period of 5 or 6 months may  well show a change in height.

keherder
Obsidian | Level 7
Good point! This is just a simulated data set, however, for a classroom project and we were told to assume heights stayed constant.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1294 views
  • 0 likes
  • 4 in conversation