10-06-2012 12:38 AM
Need some help with this code:
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);
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.
10-06-2012 02:50 AM
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;
if pstkrv>0 then bm=(seq-pstkrv+txditc);
else if pstkrv<0 then
if pstkl>0 then bm=(seq-pstkl+txditc);
else if pstkl<0 then
if pstk>0 then bm=(seq-pstk+txditc);
else if pstk<0 then bm=(seq+txditc);
else output missed_cases;
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.