11-07-2017 07:44 AM
I'm going nuts trying to figure out where my coding error is. Can anyone tell me what I'm doing wrong?
11-07-2017 08:02 AM
Its always a good idea to post test data as a datastep in the post to show what you have, and example of what you want out. Its very hard to tell from what you have posted, anything which is happening. I would maybe write it like this:
data want; set have; select (dlpp1); when (1) hb_dlpp1=0; when (2) hb_dlpp1=1; when (-99) hb_dlpp1=ifn(pdet1=1,0,1); otherwise hb_dlpp1=.; end; run;
Note how I don't use mixed case.
11-07-2017 11:02 AM
MANY THANKS FOR YOUR HELP! This fixed the specific problem, but then it handled -99 and . differently. When both are -99 hb_dlpp1 should = -99, and when one is -99 and the other ., it should = . 9 (see below):
I forced it to give me the right results by adding the additional 2 lines of code, but is there a more elegant way to do this?
if dlpp1 = -99 AND pdet1 = . then hb_dlpp1 = .;
if dlpp1 = -99 and pdet1 = -99 then hb_dlpp1 = -99;
11-07-2017 11:21 AM
Just update it to reflect your logic:
data want; set have; select (dlpp1); when (1) hb_dlpp1=0; when (2) hb_dlpp1=1; when (-99) do; if pdet=1 then hbdlpp1=1;
if pdet=2 then hpdlpp1=0;
if pdet=. then hdlpp1=.;
if pdet=-99 then hldpp1=-99; end; otherwise hb_dlpp1=.; end; run;
11-07-2017 09:55 AM
The rest of us have now officially joined you (going nuts, that is). There's nothing wrong with the code you posted. Perhaps there's something going on in the larger context of the DATA step since you posted just a portion of the DATA step.