I trying to fill in missing data in a dataset based on skip patterns and other variables but it does not seem to be doing what I want it to. I am not sure if there is a problem with my logic or the code and would appreciate some help.
Here is the code I have:
newvar_6m=.;
if oldvar=1 then newvar_6m=1;
else if oldvar=0 then newvar_6m=0;
else if dgeverc=0 then newvar_6m=0;
else if dgevere=0 then newvar_6m=0;
else if (dgeverc=.) and (dgevere=.) then newvar_6m=.;
The oldvar has 91 missing based on skip patterns because if participans answered no to previous questions then they skipped this question. However, I know that if they said no to previous questions, then the oldvar should also be no so I created code to fill in the missing and create newvar_6m.
the variable dgeverc has 0 missing, and dgevere has 44 missing. I figured the code above would fill in the missing for newvar_6m so it had no missing since all missing should be recoded to 0, what did I do wrong? I am sure it is a dumb mistake I am not picking up on so any suggestions would be appreciated.
I think if you look closely that if dgeverc =1, or any other non-zero and non-missing value, and dgevere is missing then you do not address that case. So Oldvar=., dgeverc=1 and dgevere=. has newvar_6m not assigned. Are those what your a seeing?
Run a proc freq on your data and examine the output (and post back if you still don't understand).
I can't see anything wrong with the code, so either your if/else statements are off or the data isn't what you think. Hard to tell without seeing any data or the log.
proc freq data=have;
table oldvar*dgverc*dgevere/out=summary1 list;
run;
I think if you look closely that if dgeverc =1, or any other non-zero and non-missing value, and dgevere is missing then you do not address that case. So Oldvar=., dgeverc=1 and dgevere=. has newvar_6m not assigned. Are those what your a seeing?
I figured it out, you are correct ballardw, I have a condition that is not met but where I can't fill in the missing. They answered Yes to dgeverc and dgevere but did not answer oldvar so I don't know whether it is yea or no, therefore, I must keep those as missing values. Thank you or your input. I am just glad there was nothing wrong with my code and my logic is ok.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.