BookmarkSubscribeRSS Feed
Kevin_Graduate
Calcite | Level 5
Hi, I am trying to find out why the data work.test2 has no observations, but both test3 and tes4 have c=1. Compared to test3, test2 misses one OUTPUT statement in the IF. Is this a problem? Clearly, the ELSE statement won't execute.


DATA work.test;
a=1;
b=2;
RUN;

DATA work.test2;
SET work.test;
IF a>0 THEN c=1;
ELSE
DO;
C=2;
OUTPUT;
END;
RUN;

DATA work.test3;
SET work.test;
IF a>0 THEN
DO;
c=1;
OUTPUT;
END;
ELSE
DO;
C=2;
OUTPUT;
END;
RUN;


DATA work.test4;
SET work.test;
IF a>0 THEN c=1;
ELSE
DO;
C=2;
END;
RUN;
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You only have one explicit OUTPUT statement coded inside a DO/END.

Add this SAS statement at various points in your DATA step to analyze the processing by dumping all SAS variables to your SASLOG (change/identify each unique PUTLOG with the "nn" literal-constant):

PUTLOG '>DIAG-nn>' / _ALL_;


Scott Barry
SBBWorks, Inc.
Kevin_Graduate
Calcite | Level 5
It is very helpful to use the PUTLOG _ALL_ indeed. I tried.
Reeza
Super User
Yes this is a problem, output statements are defined at compile time I believe, not execution.

Once you have an explicit output statement there is no more implicit output and you need to have an output statement where you want an output.

As you noted the else statement won't execute so there won't be any output!.
Kevin_Graduate
Calcite | Level 5
Thanks for advice, Reeza.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1352 views
  • 0 likes
  • 3 in conversation