I'm going nuts trying to figure out where my coding error is. Can anyone tell me what I'm doing wrong?
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.
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;
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.