05-23-2013 05:33 PM
I am recoding variables and am having trouble with missing data. I was to make sure if data is missing, it stays missing in the new variables so I have coded like this:
if (.<dg6fqad^=8) or (.<dg6fqd^=8) then newvar=1;
if (dg6fqad=.) and (dg6fqd=.) then newvar=.;
if (.<dg6fqe^=8) then newvar1=1;
if dg6fqe=. then newvar1=.;
This codes makes missing data =0, how do I correct this?
05-23-2013 05:53 PM
Actually, for this, the missing variables are still getting coded wrong, is there something else I need to do? I am sure it is simple but I keep getting it wrong.
if .<dg6fqe^=8 then newvar=1;
else if dg6fqe=. then newvar=.;
else newvar=0 ;
05-23-2013 05:56 PM
Check if its missing first and then if its not equal to 8 second.
That seems to be what your code is trying to do.
It's a bit weird to see a less than sign and a not equal to in the same line so I'm not sure what that would be evaluating to.
if dg6fqe=. then newvar=.
else if dg6fqe ne 8 then newvar=1;
05-23-2013 06:13 PM
hm, ok that makes sense and I see why that coding is better than mine but it is still not working. I have 79 missing values and should have 62 in my 0 category but it is giving me a 0=141 and no missing. I can't figure out what is going on. Thanks for your input.
05-23-2013 06:29 PM
Sometimes instead of trying to get all of several multiple variable logics to work and exclude at each step I go through the main logic. Then add:
if dg6fqe=. then newvar=. ;
After the main assignments. It may not be elegant but it easy to understand and maintain.
05-23-2013 06:40 PM
I just figured it out, for some reason I had two instances of the code in the data step. The second coding was incorrect and lumping the missing in with the 0 category and was overriding the first, correct coding. Dumb oversight on my part, thank you for your help and patience! I appreciate it!
Need further help from the community? Please ask a new question.