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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.