Hello!
Wondering if anyone could help me with this. Here is a photo of my data set:
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!
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;
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;
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.