BookmarkSubscribeRSS Feed
jberkes
Calcite | Level 5
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
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
jberkes
Calcite | Level 5
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
jberkes
Calcite | Level 5
Thanks for your help Scott.

I found what I needed using your seach suggestions.


Jim
deleted_user
Not applicable
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) ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 699 views
  • 0 likes
  • 3 in conversation