I'm in bit of a pickle here and turning to you all for help. I'm a SAS beginner so pardon me if this is a very basic question. Basically, I have this dataset:
ID Gender Type
1 F X
F Y
2 F Y
M Y
F X
Both the first two observations "belong" to ID=1 and the last three observations "belong" to ID=2. How do I fill in the missing ID values? I've tried using retain but SAS won't let me run any data step where I have a "by id" statement because this dataset isn't sorted by id. However, I can't sort it by ID because then I lose the grouping.
Any solutions here?
data want;
set have;
retain _id;
if not missing(id) then _id=id;
else id=_id;
drop _id;
run;
data want;
set have;
retain _id;
if not missing(id) then _id=id;
else id=_id;
drop _id;
run;
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 save with the early bird rate—just $795!
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.