BookmarkSubscribeRSS Feed
Benn
Calcite | Level 5

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!

1 REPLY 1
Patrick
Opal | Level 21

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 602 views
  • 0 likes
  • 2 in conversation