Help using Base SAS procedures

A question

Reply
Occasional Contributor
Posts: 13

A question

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;
Super Contributor
Super Contributor
Posts: 3,174

Re: A question

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.
Occasional Contributor
Posts: 13

Re: A question

It is very helpful to use the PUTLOG _ALL_ indeed. I tried.
Super User
Posts: 17,750

Re: A question

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!.
Occasional Contributor
Posts: 13

Re: A question

Thanks for advice, Reeza.
Ask a Question
Discussion stats
  • 4 replies
  • 284 views
  • 0 likes
  • 3 in conversation