Hi Guys,
Need some help with this code:
DATA Rawcompustat8;
SET work.Rawcompustat6;
IF PSTKRV>0 THEN BM=(SEQ-PSTKRV+TXDITC);
IF PSTKRV<0 and PSTKL>0 THEN BM=(SEQ-PSTKL+TXDITC);
IF PSTKRV<0 and PSTKL<0 and PSTK>0 THEN BM=(SEQ-PSTK+TXDITC);
IF PSTKRV<0 and PSTKL<0 and PSTK<0 THEN BM=(SEQ+TXDITC);
RUN;
This code works fine for the first 3 sentences of "IF". However, the last "IF" gave outputs of periods (.)
I can't figure out where I went wrong.
Thanks guys!
I've re-coded your IF sequence a bit. It still does exactly the same - I just find it easier to debug.
data rawcompustat8 missed_cases;
set work.rawcompustat6;
if pstkrv>0 then bm=(seq-pstkrv+txditc);
else if pstkrv<0 then
do;
if pstkl>0 then bm=(seq-pstkl+txditc);
else if pstkl<0 then
do;
if pstk>0 then bm=(seq-pstk+txditc);
else if pstk<0 then bm=(seq+txditc);
else output missed_cases;
end;
end;
output rawcompustat8;
run;
I can see 2 reasons for ending up with missings.
1. You don't cover cases where your "selection" variables are exactly zero - so there "BM" will be missing
2. For the case where "IF PSTKRV<0 and PSTKL<0 and PSTK<0" is true one or both of the 2 variables you're summing is missing - so the result stored in BM would be missing (which is represented as a '.').
I've added a table for missed cases. In there will be all rows you've missed which should allow you to determine why your code is not working as expected.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.