PRINT Procedure

Example 6: Limiting the Number of Sums in a Report

Features:

BY statement

SUM statement

SUMBY statement

Other features:

FORMAT statement

LABEL statement

ODS PDF statement

SORT procedure

TITLE statement

Data set: EXPREV

Details

This example demonstrates the following tasks:
  • creates a separate section of the report for each combination of sale type and sale date
  • sums quantities and retail prices only for each sale type and for all sale types, not for individual dates
  • creates a PDF file

Program: Creating a PDF File

options nodate pageno=1 obs=10;
ods html close;
ods pdf file='your_file.pdf';
proc sort data=exprev;
   by sale_type order_date;
run;
proc print data=exprev noobs sumlabel;
   by sale_type order_date;
   sum price quantity;
   sumby sale_type;
   label sale_type='Sale Type' order_date='Sale Date';
   format price dollar10.2 cost dollar10.2;
   title 'Retail and Quantity Totals for Each Sale Type';
run;
ods pdf close;

Program Description

Set the SAS system options.The NODATE option suppresses the display of the date and time in the output. The PAGENO= option specifies the starting page number. The OBS= option specifies the number of observations to be displayed.
options nodate pageno=1 obs=10;
Produce PDF output and specify the file to store the output in.The ODS HTML CLOSE statement closes the default destination. The ODS PDF statement opens the PDF destination and creates a file that contains PDF output. The FILE= argument specifies the external file that contains the PDF output.
ods html close;
ods pdf file='your_file.pdf';
Sort the data set.PROC SORT sorts the observations by Sales_Type and Order_Date.
proc sort data=exprev;
   by sale_type order_date;
run;
Print the report and remove the observation numbers.NOOBS suppresses the printing of observation numbers at the beginning of the rows. SUMLABEL uses the label for the BY variables on the summary line of each BY group.
proc print data=exprev noobs sumlabel;
Sum the values for each region.The SUM and BY statements work together to sum the values of Price and Quantity for each BY group as well as for the whole report. The SUMBY statement limits the subtotals to one for each type of sale.
   by sale_type order_date;
   sum price quantity;
   sumby sale_type;
Assign labels to specific variables.The LABEL statement associates a label with the variables Sale_Type and Order_Date for the duration of the PROC PRINT step. These labels are used in the BY group title or the summary line.
   label sale_type='Sale Type' order_date='Sale Date';
Assign a format to the necessary variables and specify a title.The FORMAT statement assigns the COMMA10. format to Cost and Price for this report. The TITLE statement specifies a title.
   format price dollar10.2 cost dollar10.2;
   title 'Retail and Quantity Totals for Each Sale Type';
run;
Close the PS destination. The ODS PDF CLOSE statement closes the PDF destination.
ods pdf close;

Output: PDF

Limiting the Number of Sums in a Report: PDF Output
Limiting the Number of Sums in a Report: PDF Output

Program: Creating a PDF Report with the STYLE Option

options nodate pageno=1 linesize=80 pagesize=40 obs=10;
ods pdf file='your_file.pdf';
proc sort data=exprev;
   by sale_type order_date;
run;
proc print data=exprev noobs;
   by sale_type order_date;
   
   sum price / style(TOTAL) = [background =blue color=white];
   sum quantity / style(GRANDTOTAL) = [background =yellow color=red];
   sumby sale_type;
   label sale_type='Sale Type' order_date='Sale Date';
   format price dollar10.2 cost dollar10.2;
   title 'Retail and Quantity Totals for Each Sale Type';
run;
ods pdf close;

Program Description

options nodate pageno=1 linesize=80 pagesize=40 obs=10;
ods pdf file='your_file.pdf';
proc sort data=exprev;
   by sale_type order_date;
run;
proc print data=exprev noobs;
   by sale_type order_date;
   
Create stylized PDF output. The STYLE option in the first SUM statement specifies that the background color of cells containing totals for the variable Price be changed to blue and the font color be changed to white. The STYLE option in the second SUM statement specifies that the background color of the cell containing the grand total for the Quantity variable be changed to yellow and the font color be changed to red.
   sum price / style(TOTAL) = [background =blue color=white];
   sum quantity / style(GRANDTOTAL) = [background =yellow color=red];
   sumby sale_type;
   label sale_type='Sale Type' order_date='Sale Date';
   format price dollar10.2 cost dollar10.2;
   title 'Retail and Quantity Totals for Each Sale Type';
run;
ods pdf close;

Output: PDF with Styles

Limiting the Number of Sums in a Report: PostScript Output Using Styles
Limiting the Number of Sums in a Report: PostScript Output Using Styles