02-02-2017 09:39 PM - last edited on 02-03-2017 12:15 AM by Tom
What statements do I add after the DO statement to randomly impute gender values of 'F' and 'M' (with 60% of people being female).
if geneder = ' ' then do;
02-02-2017 10:06 PM
The below sample code should guide you through.
data have ; input id sex $ ; datalines ; 23 M 25 M 26 F 27 F 28 F ; RUN ; DATA WANT; length Y $10. ; set have ; if sex='M' then do Y='Male' ; end ; else if sex = 'F' then do Y='Female' ; end ; run ; proc print data=want; run;
02-02-2017 10:23 PM
Use the random number generator RAND which returns a random number uniformly distributed between 0 and 1 :
data imputed; set missing; if missing(gender) then if rand("uniform") < 0.6 then gender = "F"; else gender ="M"; run;
02-03-2017 12:15 AM
Same thing, under the hood. You could also use "table".
I was wondering about that...it's been a while since I've studied random number generators
02-03-2017 12:25 AM
Of course, I haven't seen what's under the hood, I can only guess. But as far as I know, all RAND generators are based on transformations of the uniform generator.