PRINT Procedure

Example 1: Selecting Variables to Print

Features:
PROC PRINT statement options: :
BLANKLINE
DOUBLE
STYLE

VAR statement

Other features:

DATA step

FOOTNOTE statement

ODS HTML statement

OPTIONS statement

TITLE statement

Data set: EXPREV

Details

This example demonstrates the following tasks:
  • selects three variables for the reports
  • uses variable labels as column headings
  • double spaces between rows of the report in the Listing output
  • creates a default HTML report
  • creates a stylized HTML report

Program: Creating an HTML Report

options obs=10;
proc print data=exprev;
   var country price sale_type;
   title 'Monthly Price Per Unit and Sale Type for Each Country';
   footnote '*prices in USD';
run;

Program Description

HTML is the default destination when SAS opens.
Set the OBS= system option to process 10 observations.
options obs=10;
Print the output The VAR statement specifies the variables to print.
proc print data=exprev;
   var country price sale_type;
   title 'Monthly Price Per Unit and Sale Type for Each Country';
   footnote '*prices in USD';
run;

Output: HTML

Selecting Variables: Default HTML Output
Selecting Variables: Default HTML Output

Program: Creating an HTML Report with the STYLE and BLANKLINE Options

options nodate obs=5;
ods html file='your_file_styles.html';
proc print data=exprev
   style(header) = {fontstyle=italic color= green}
   style(obs) = {backgroundcolor=#5959ab color=white}
   blankline=(count=1 style={backgroundcolor=cx456789});
   var country price sale_type;
   title 'Monthly Price Per Unit and Sale Type for Each Country';
   footnote '*prices in USD';
run;

Program Description

You can go a step further and add more formatting to your HTML output. The following example uses the STYLE option to add shading and spacing to your HTML report.
options nodate obs=5;
ods html file='your_file_styles.html';
Create stylized HTML output. The first STYLE option specifies that the column headings be written in green italic font. The second STYLE option specifies that ODS change the color of the background of the observations column to the RGB color code 5959AB. The BLANKLINE option specifies to add a blank line between each observation and use a background color of the RGB color code 456789. Because a style has not been defined for the obsheader style element, the Obs column heading in the output uses the default style color and not green.
proc print data=exprev
   style(header) = {fontstyle=italic color= green}
   style(obs) = {backgroundcolor=#5959ab color=white}
   blankline=(count=1 style={backgroundcolor=cx456789});
   var country price sale_type;
   title 'Monthly Price Per Unit and Sale Type for Each Country';
   footnote '*prices in USD';
run;

Output: HTML Output with Styles

Selecting Variables: HTML Output Using Styles
Selecting Variables: HTML Output Using Styles

Program: Creating a Listing Report

options nodate pageno=1 linesize=80 pagesize=30 obs=10;
ods html close;
ods listing;
proc print data=exprev double;
   var country price sale_type;
   title 'Monthly Price Per Unit and Sale Type for Each Country';
   footnote '*prices in USD';
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 display.
options nodate pageno=1 linesize=80 pagesize=30 obs=10;
Close the HTML destination and open the Listing destination.HTML is the default destination when you start SAS. To create only a listing report, you can close the HTML destination and open the Listing destination.
ods html close;
ods listing;
Print the data set EXPREV. EXPREV contains information about a company's product order type and price per unit for two months. DOUBLE inserts a blank line between observations. The DOUBLE option has no effect on the HTML output.
proc print data=exprev double;
Select the variables to include in the report. The VAR statement creates columns for Country, Price, and Sale_Type, in that order.
   var country price sale_type;
Specify a title and a footnote. The TITLE statement specifies the title for the report. The FOOTNOTE statement specifies a footnote for the report.
   title 'Monthly Price Per Unit and Sale Type for Each Country';
   footnote '*prices in USD';
run;
Close the Listing destination and reopen the HTML destination.When you close and reopen the HTML destination, SAS saves HTML output to the current directory and not the Work library.
ods listing close;
ods html;

Output: Listing

By default, PROC PRINT identifies each observation by number under the column heading Obs.
Selecting Variables: Listing Output
             Monthly Price Per Unit and Sale Type for Each Country             1

                                                          Sale_
               Obs    Country                   Price      Type

                 1    Antarctica                 92.6    Internet

                 2    Puerto Rico                51.2    Catalog

                 3    Virgin Islands (U.S.)      31.1    In Store

                 4    Aruba                     123.7    Catalog

                 5    Bahamas                   113.4    Catalog

                 6    Bermuda                    41.0    Catalog

                 7    Belize                    146.4    In Store

                 8    British Virgin Islands     40.2    Catalog

                 9    Canada                     11.8    Catalog

                10    Cayman Islands             71.0    In Store




                                 *prices in USD