Previous Page | Next Page

The PRINT Procedure

PROC PRINT Statement


PROC PRINT <option(s)>;

Task Option
Specify text for the HTML contents link to the output CONTENTS=
Specify the input data set DATA=
Control general format

Write a blank line after n observations BLANKLINE=

Write a blank line between observations DOUBLE

Print the number of observations in the data set, in BY groups, or both, and specify explanatory text to print with the number N=

Suppress the column in the output that identifies each observation by number NOOBS

Specify a column heading for the column that identifies each observation by number OBS=

Round unformatted numeric values to two decimal places ROUND
Control page format

Format the rows on a page ROWS=

Use each variable's formatted width as its column width on all pages WIDTH=UNIFORM
Control column format

Control the orientation of the column headings HEADING=

Use variables' labels as column headings LABEL or SPLIT

Specify the split character, which controls line breaks in column headings SPLIT=

Specify one or more style elements for the Output Delivery System to use for different parts of the report STYLE

Display the BY variable label on the summary line SUMLABEL

Determine the column width for each variable WIDTH=


Options

BLANKLINE= n
BLANKLINE= (COUNT=n <STYLE= [style-attibute-specification(s)] > )

specifies to insert a blank line after every n observations. The observation count is reset at the beginning of each page and at the beginning of each BY group for all ODS destinations except for the RTF and PDF destination. For the RTF and PDF destinations, the observation count is reset only at the beginning of a BY group.

n | COUNT = n

specifies the observation number after which SAS inserts a blank line.

STYLE = [ style-attribute-specification(s) ]

specifies the style to use for the blank line.

Default: DATA
Tip: You can use the BACKGROUNDCOLOR style element to make a visual distinction between observations using color.
See: The STYLE option for valid style attributes.
Featured in: Selecting Variables to Print
CONTENTS=link-text

specifies the text for the links in the HTML contents file to the output produced by the PROC PRINT statement. For information about HTML output, see Files Produced by the HTML Destination and ODS HTML Statement in SAS Output Delivery System: User's Guide.

Restriction: CONTENTS= does not affect the HTML body file. It affects only the HTML contents file.
DATA=SAS-data-set

specifies the SAS data set to print.

Main discussion: Input Data Sets
DOUBLE

writes a blank line between observations.

Alias: D
Restriction: This option is valid only for the listing destination.
Featured in: Selecting Variables to Print
HEADING=direction

controls the orientation of the column headings, where direction is one of the following:

HORIZONTAL

prints all column headings horizontally.

Alias: H
VERTICAL

prints all column headings vertically.

Alias: V
Default: Headings are either all horizontal or all vertical. If you omit HEADING=, PROC PRINT determines the direction of the column headings as follows:
  • If you do not use LABEL, spacing specifies whether column headings are vertical or horizontal.

  • If you use LABEL and at least one variable has a label, all headings are horizontal.

LABEL

uses variables' labels as column headings.

Alias: L
Default: If you omit LABEL, PROC PRINT uses the variable's name as the column heading even if the PROC PRINT step contains a LABEL statement. If a variable does not have a label, PROC PRINT uses the variable's name as the column heading.
Interaction: By default, if you specify LABEL and at least one variable has a label, PROC PRINT prints all column headings horizontally. Therefore, using LABEL might increase the number of pages of output. (Use HEADING=VERTICAL in the PROC PRINT statement to print vertical column headings.)
Interaction: PROC PRINT sometimes conserves space by splitting labels across multiple lines. Use SPLIT= in the PROC PRINT statement to control where these splits occur. You do not need to use LABEL if you use SPLIT=.
Tip: To create a blank column heading for a variable, use this LABEL statement in your PROC PRINT step:
   label variable-name='00'x;
See also: For information on using the LABEL statement to create temporary labels in procedures see Statements with the Same Function in Multiple Procedures.

For information about using the LABEL statement in a DATA step to create permanent labels, see LABEL Statement in SAS Language Reference: Dictionary.

Featured in: Creating Separate Sections of a Report for Groups of Observations

Note:   The SAS system option LABEL must be in effect in order for any procedure to use labels. For more information see LABEL System Option in SAS Language Reference: Dictionary  [cautionend]

N<="string-1" <"string-2">>

prints the number of observations in the data set, in BY groups, or both and specifies explanatory text to print with the number.

N Option Use PROC PRINT Action
with neither a BY nor a SUM statement prints the number of observations in the data set at the end of the report and labels the number with the value of string-1.
with a BY statement prints the number of observations in the BY group at the end of each BY group and labels the number with the value of string-1.
with a BY statement and a SUM statement prints the number of observations in the BY group at the end of each BY group and prints the number of observations in the data set at the end of the report. The numbers for BY groups are labeled with string-1; the number for the entire data set is labeled with string-2.

Featured in: Customizing Text in Column Headings (alone)

Creating Separate Sections of a Report for Groups of Observations (with a BY statement)

Summing Numeric Variables with One BY Group (with a BY statement and a SUM statement)

NOOBS

suppresses the observation number in the output.

Featured in: Creating Separate Sections of a Report for Groups of Observations
OBS="column-header"

specifies a column heading for the column that identifies each observation by number.

Tip: OBS= honors the split character (see the discussion of SPLIT= ).
Featured in: Customizing Text in Column Headings
ROUND

rounds unformatted numeric values to two decimal places. (Formatted values are already rounded by the format to the specified number of decimal places.) For both formatted and unformatted variables, PROC PRINT uses these rounded values to calculate any sums in the report.

If you omit ROUND, PROC PRINT adds the actual values of the rows to obtain the sum even though it displays the formatted (rounded) values. Any sums are also rounded by the format, but they include only one rounding error, that of rounding the sum of the actual values. The ROUND option, on the other hand, rounds values before summing them, so there might be multiple rounding errors. The results without ROUND are more accurate, but ROUND is useful for published reports where it is important for the total to be the sum of the printed (rounded) values.

Be aware that the results from PROC PRINT with the ROUND option might differ from the results of summing the same data with other methods such as PROC MEANS or the DATA step. Consider a simple case in which

  • the data set contains three values for X: .003, .004, and .009.

  • X has a format of 5.2.

Depending on how you calculate the sum, you can get three different answers: 0.02, 0.01, and 0.016. The following figure shows the results of calculating the sum with PROC PRINT (without and with the ROUND option) and PROC MEANS.

Three Methods of Summing Variables

[Three Methods of Summing Variables]

Notice that the sum produced without the ROUND option (.02) is closer to the actual result (0.16) than the sum produced with ROUND (0.01). However, the sum produced with ROUND reflects the numbers displayed in the report.

Alias: R
CAUTION:
Do not use ROUND with PICTURE formats.

ROUND is for use with numeric values. SAS procedures treat variables that have picture formats as character variables. Using ROUND with such variables might lead to unexpected results.  [cautionend]

ROWS= page-format

formats rows on a page. Currently, PAGE is the only value that you can use for page-format:

PAGE

prints only one row of variables for each observation per page. When you use ROWS=PAGE, PROC PRINT does not divide the page into sections; it prints as many observations as possible on each page. If the observations do not fill the last page of the output, PROC PRINT divides the last page into sections and prints all the variables for the last few observations.

Restriction: Physical page size does not mean the same thing in HTML output as it does in traditional procedure output. Therefore, HTML output from PROC PRINT appears the same whether you use ROWS=.
Tip: The PAGE value can reduce the number of pages in the output if the data set contains large numbers of variables and observations. However, if the data set contains a large number of variables but few observations, the PAGE value can increase the number of pages in the output.
See also: Page Layout for discussion of the default layout.
Featured in: Controlling the Layout of a Report with Many Variables
SPLIT='split-character'

specifies the split character, which controls line breaks in column headings. It also uses labels as column headings. PROC PRINT breaks a column heading when it reaches the split character and continues the header on the next line. The split character is not part of the column heading although each occurrence of the split character counts toward the 256-character maximum for a label.

Alias: S=
Interaction: You do not need to use both LABEL and SPLIT= because SPLIT= implies the use of labels.
Interaction: The OBS= option honors the split character. (See the discussion of OBS=.)
Featured in: Customizing Text in Column Headings

Note:   PROC PRINT does not split labels of BY variables in the heading preceding each BY group even if you specify SPLIT=. Instead, PROC PRINT replaces the split character with a blank.   [cautionend]

STYLE <(location(s))>=<style-element-name><[style-attribute-specification(s)]>

specifies the style element to use for the specified locations in the report. You can use braces ({ and }) instead of square brackets ([ and ]).

location

identifies the part of the report that the STYLE option affects. The following table shows the available locations and the other statements in which you can specify them.

Note:   Style specifications in a statement other than the PROC PRINT statement override the same style specification in the PROC PRINT statement. However, style attributes that you specify in the PROC PRINT statement are inherited, provided that you do not override the style with style specifications in another statement. For example, if you specify a blue background and a white foreground for all column headings in the PROC PRINT statement, and you specify a gray background for the column headings of a variable in the VAR statement, the background for that particular column heading is gray, and the foreground is white (as specified in the PROC PRINT statement).  [cautionend]

Specifying Locations in the STYLE Option
Location Affected Report Part Can Also Be Used In These Statements
BYLABEL the label for the BY variable on the line containing the SUM totals none
DATA the cells of all columns VAR

ID

SUM

GRANDTOTAL the SUM line containing the grand totals for the whole report SUM
HEADER all column headings VAR

ID

SUM

N N= table and contents none
OBS the data in the OBS column none
OBSHEADER the header of the OBS column none
TABLE the structural part of the report - that is, the underlying table used to set things like the width of the border and the space between cells none
TOTAL the SUM line containing totals for each BY group SUM

For your convenience and for consistency with other procedures, the following table shows aliases for the different locations.

Aliases for Locations
Location Aliases
BYLABEL BYSUMLABEL

BYLBL

BYSUMLBL

DATA COLUMN

COL

GRANDTOTAL GRANDTOT

GRAND

GTOTAL

GTOT

HEADER HEAD

HDR

N none
OBS OBSDATA

OBSCOLUMN

OBSCOL

OBSHEADER OBSHEAD

OBSHDR

TABLE REPORT
TOTAL TOT

BYSUMLINE

BYLINE

BYSUM

style-element-name

is the name of a style element that is part of a style definition that is registered with the Output Delivery System. SAS provides some style definitions. Users can create their own style definitions with PROC TEMPLATE.

When style elements are processed, more specific style elements override less specific style elements.

Default: The following table shows the default style element for each location.
The Default Style Element for Each Location in PROC PRINT
Location Default Style Element
BYLABEL Header
DATA Data (for all but ID statement)

RowHeader (for ID statement)

GRANDTOTAL Header
HEADER Header
N NoteContent
OBS RowHeader
OBSHEADER Header
TABLE Table
TOTAL Header

style-attribute-specification

describes the style attribute to change. Each style-attribute-specification has this general form:

style-attribute-name=style-attribute-value

You can set these style attributes in the TABLE location:

BACKGROUNDCOLOR= FONTWIDTH=*
BACKGROUNDIMAGE= COLOR=*
BORDERCOLOR= FRAME=
BORDERCOLORDARK= HTMLCLASS=
BORDERCOLORLIGHT= TEXTALIGN=
BORDERWIDTH= OUTPUTWIDTH=
CELLPADDING= POSTHTML=
CELLSPACING= POSTIMAGE=
FONT=* POSTTEXT=
FONTFAMILY=* PREHTML=
FONTSIZE=* PREIMAGE=
FONTSTYLE=* PRETEXT=
FONTWEIGHT=* RULES=

*When you use these attributes, they affect only the text that is specified with the PRETEXT=, POSTTEXT=, PREHTML=, and POSTHTML= attributes. To alter the foreground color or the font for the text that appears in the table, you must set the corresponding attribute in a location that affects the cells rather than the table.

You can set these style attributes in all locations other than TABLE:

ASIS= FONTWIDTH=
BACKGROUNDCOLOR= HREFTARGET=
BACKGROUNDIMAGE= CLASS=
BORDERCOLOR= TEXTALIGN=
BORDERCOLORDARK= NOBREAKSPACE=
BORDERCOLORLIGHT= POSTHTML=
BORDERWIDTH= POSTIMAGE=
HEIGHT= POSTTEXT=
CELLWIDTH= PREHTML=
FLYOVER= PREIMAGE=
FONT= PRETEXT=
FONTFAMILY= PROTECTSPECIALCHARACTERS=
FONTSIZE= TAGATTR=
FONTSTYLE= URL=
FONTWEIGHT= VERTICALALIGN=

For information about style attributes, see DEFINE STYLE statement in SAS Output Delivery System: User's Guide.

Restriction: This option affects all destinations except Listing and Output.
SUMLABEL

uses BY variable labels in the summary line in place of the BY variable name.

Default: If you omit SUMLABEL, PROC PRINT uses the BY variable names in the summary line.
Featured in:

Summing Numeric Variables with One BY Group

Summing Numeric Variables with Multiple BY Variables

Note:   The SAS system option LABEL must be in effect in order for any procedure to use labels. For more information, see the LABEL System Option in SAS Language Reference: Dictionary:  [cautionend]

UNIFORM

See WIDTH=UNIFORM.

WIDTH=column-width

determines the column width for each variable. The value of column-width must be one of the following:

FULL

uses a variable's formatted width as the column width. If the variable does not have a format that explicitly specifies a field width, PROC PRINT uses the default width. For a character variable, the default width is the length of the variable. For a numeric variable, the default width is 12. When you use WIDTH=FULL, the column widths do not vary from page to page.

Tip: Using WIDTH=FULL can reduce execution time.
MINIMUM

uses for each variable the minimum column width that accommodates all values of the variable.

Alias: MIN
UNIFORM

uses each variable's formatted width as its column width on all pages. If the variable does not have a format that explicitly specifies a field width, PROC PRINT uses the widest data value as the column width. When you specify WIDTH=UNIFORM, PROC PRINT normally needs to read the data set twice. However, if all the variables in the data set have formats that explicitly specify a field width (for example, BEST12. but not BEST.), PROC PRINT reads the data set only once.

Alias: U
Tip: If the data set is large and you want a uniform report, you can save computer resources by using formats that explicitly specify a field width so that PROC PRINT reads the data only once.
Tip: WIDTH=UNIFORM is the same as UNIFORM.
Restriction: When not all variables have formats that explicitly specify a width, you cannot use WIDTH=UNIFORM with an engine that supports concurrent access if another user is updating the data set at the same time.
UNIFORMBY

formats all columns uniformly within a BY group, using each variable's formatted width as its column width. If the variable does not have a format that explicitly specifies a field width, PROC PRINT uses the widest data value as the column width.

Alias: UBY
Restriction: You cannot use UNIFORMBY with a sequential data set.
Default: If you omit WIDTH= and do not specify the UNIFORM option, PROC PRINT individually constructs each page of output. The procedure analyzes the data for a page and decides how best to display them. Therefore, column widths might differ from one page to another.
Tip: Column width is affected not only by variable width but also by the length of column headings. Long column headings might lessen the usefulness of WIDTH=.
See also: For a discussion of default column widths, see Column Width.

Previous Page | Next Page | Top of Page