Help using Base SAS procedures

proselyte needs help with conditional printing.

Reply
Occasional Contributor
Posts: 6

proselyte needs help with conditional printing.

I only want proc print to create a print report if a sum amount from the data step is greater than zero.

The customer doesn't want the report created if the fields on the report are all zeros.

Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: proselyte needs help with conditional printing.

Without using macro language, you can execute a DATA that determines your "print" or "no print" condition, then use SAS CALL EXECUTE to dynamically generate the PROC PRINT which would be executed after the DATA step completes.

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 6

Re: proselyte needs help with conditional printing.

I understand the concept of Scott's explanation but I don't know the syntax for implementing it.

Can someone fix up this code to not print when the Total is 0?

Data A;
Input YEAR SALES COST;
RETAIN Total 0;
Total = SUM(Total, SALES);

CARDS;
2009 0 0
2009 0 0


PROC PRINT DATA=A;

Your help would be greatly appreciated.
Thanks
Jim Berkes
Super Contributor
Super Contributor
Posts: 3,174

Re: proselyte needs help with conditional printing.

Your PROC PRINT code would need to be contained in a SAS variable (one option), and then if you find an unsuitable condition, do not invoke the CALL EXECUTE statement.

The SAS support website http://support.sas.com/ has several topic-related papers for example code and conceptual reference, as well as a SAS-hosted documentation. Or consider the Google advanced search argument below which reveals several search-matches on the topic:

call execute site:sas.com


Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 6

Re: proselyte needs help with conditional printing.

Thanks for your help Scott.

I found what I needed using your seach suggestions.


Jim
N/A
Posts: 0

Re: proselyte needs help with conditional printing.

Data XyZ ;
Input ID $ tot cost;
cards;
ABC 10 100
XYZ 20 200
;
RUN;
Data ABC ;
Input ID $ tot cost;
cards;
ABC 0 0
XYZ 0 0
;
RUN;

%Macro A(dsn) ;
proc sql noprint;
select sum(tot) into : totsum from &dsn;
quit;
%if (&totsum) > 0 %then %do;
proc print data = &dsn ;run;
%end ;
%else %do ;
data _null_;
file print notitle ls=80;;
Put @50 "Data Set &DSN has zero Total Cost.";
Run;
%end;
%Mend A;
%A(xyz) ;
%A(ABC) ;
Ask a Question
Discussion stats
  • 5 replies
  • 124 views
  • 0 likes
  • 3 in conversation