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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.