PRINT Procedure

Example 2: Customizing Text in Column Headings

Features:
PROC PRINT statement options: :
N
OBS=
SPLIT=
STYLE

VAR statement option: : STYLE

Other features:

LABEL statement

ODS PDF statement

FORMAT statement

TITLE statement

Data set: EXPREV

Details

This example demonstrates the following tasks:
  • customizes and underlines the text in column headings for variables
  • customizes the column heading for the column that identifies observations by number
  • shows the number of observations in the report
  • writes the values of the variable Price with dollar signs and periods.
  • creates a Listing report
  • creates a default PDF report
  • creates a stylized PDF report

Program: Creating a Listing Report

options nodate pageno=1 linesize=80 pagesize=30 obs=10;
ods html close;
ods listing;
proc print data=exprev split='*' n
obs='Observation*Number*===========';
   var country sale_type price;
   label country='Country Name**============'
         sale_type='Order Type**=========='
         price='Price Per Unit*in USD*==============';
   format price dollar10.2;
   title 'Order Type and Price Per Unit in Each Country';
run;
ods listing close;
ods html;

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 LINESIZE= option specifies the output line length, and the PAGESIZE= option specifies the number of lines on an output page. The OBS= option specifies the number of observations to be displayed.
options nodate pageno=1 linesize=80 pagesize=30 obs=10;
Close the HTML destination and open the Listing destination.By default, the HTML destination is open.
ods html close;
ods listing;
Print the report and define the column headings. SPLIT= identifies the asterisk as the character that starts a new line in column headings. The N option prints the number of observations at the end of the report. OBS= specifies the column heading for the column that identifies each observation by number. The split character (*) starts a new line in the column heading. The equal signs (=) in the value of OBS= underlines the column heading.
proc print data=exprev split='*' n
obs='Observation*Number*===========';
Select the variables to include in the report. The VAR statement creates columns for Country, Sale_Type, and Price, in that order.
   var country sale_type price;
Assign the variables' labels as column headings. The LABEL statement associates a label with each variable for the duration of the PROC PRINT step. When you use the SPLIT= option in the PROC PRINT statement, the procedure uses labels for column headings. The split character (*) starts a new line in the column heading. The equal signs (=) in the labels underlines the column headings.
   label country='Country Name**============'
         sale_type='Order Type**=========='
         price='Price Per Unit*in USD*==============';
Specify a title for the report, and format any variable containing numbers. The FORMAT statement assigns the DOLLAR10.2 format to the variable Price in the report. The TITLE statement specifies a title.
   format price dollar10.2;
   title 'Order Type and Price Per Unit in Each Country';
run;
Close the Listing destination and re-open the HTML destination.
ods listing close;
ods html;

Output: Listing

Customizing Column Headings: Listing Output
                Order Type and Price Per Unit in Each Country                 1

     Observation    Country Name              Order Type    Price Per Unit
        Number                                                  in USD
     ===========    ============              ==========    ==============

           1        Antarctica                 Internet           $92.60
           2        Puerto Rico                Catalog            $51.20
           3        Virgin Islands (U.S.)      In Store           $31.10
           4        Aruba                      Catalog           $123.70
           5        Bahamas                    Catalog           $113.40
           6        Bermuda                    Catalog            $41.00
           7        Belize                     In Store          $146.40
           8        British Virgin Islands     Catalog            $40.20
           9        Canada                     Catalog            $11.80
          10        Cayman Islands             In Store           $71.00

                                     N = 10

Program: Creating a PDF Report

options nodate pageno=1 linesize=80 pagesize=40 obs=10;
ods pdf file='your_file.pdf';
proc print data=exprev split='*' n obs='Observation*Number*===========';
   var country sale_type price;
   label country='Country Name**============'
         sale_type='Order Type**=========='
         price='Price Per Unit in USD**==============';
   
   format price dollar10.2;
   title 'Order Type and Price Per Unit in Each Country';
run;
ods pdf close;

Program Description

You can easily create PDF output by adding a few ODS statements. In the following example, ODS statements were added to produce PDF output.
options nodate pageno=1 linesize=80 pagesize=40 obs=10;
Create PDF output and specify the file to store the output in.The ODS PDF statement opens the PDF destination and creates PDF output. The FILE= argument specifies the external file that contains the PDF output.
ods pdf file='your_file.pdf';
proc print data=exprev split='*' n obs='Observation*Number*===========';
   var country sale_type price;
   label country='Country Name**============'
         sale_type='Order Type**=========='
         price='Price Per Unit in USD**==============';
   
   format price dollar10.2;
   title 'Order Type and Price Per Unit in Each Country';
run;
Close the PDF destination. The ODS PDF CLOSE statement closes the PDF destination.
ods pdf close;

Output: PDF

Customizing Column Heading: Default PDF Output
Customizing Column Heading: Default 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 print data=exprev split='*' n obs='Observation*Number*==========='
     style(n) = {fontstyle=italic backgrouncolor= blue}
     style(header obs obsheader) = {backgrouncolor=yellow color=blue};
   var country sale_type price / style (data)= [ background = gray ];
   label country='Country Name**====='
         sale_type='Order Type**====='
         price='Price Per Unit in USD**========';
   format price dollar10.2;
run;
title 'Order Type and Price Per Unit in Each Country';
ods pdf close;

Program Description

options nodate pageno=1 linesize=80 pagesize=40 obs=10;
ods pdf file='your_file.pdf';
Create stylized PDF output. The first STYLE option specifies that the background color of the cell containing the value for N be changed to blue and that the font style be changed to italic. The second STYLE option specifies that the background color of the observation column, the observation header, and the other variable's headers be changed to gray.
proc print data=exprev split='*' n obs='Observation*Number*==========='
     style(n) = {fontstyle=italic backgrouncolor= blue}
     style(header obs obsheader) = {backgrouncolor=yellow color=blue};
Create stylized PDF output. The STYLE option changes the color of the cells containing data to gray.
   var country sale_type price / style (data)= [ background = gray ];
   label country='Country Name**====='
         sale_type='Order Type**====='
         price='Price Per Unit in USD**========';
   format price dollar10.2;
run;
title 'Order Type and Price Per Unit in Each Country';
Close the PDF destination. The ODS PDF CLOSE statement closes the PDF destination.
ods pdf close;

Output: PDF Report with Styles

Customizing Column Headings: PDF Using Styles
Customizing Column Headings: PDF Using Styles