PRINT Procedure

PROC PRINT Statement

Prints observations in a SAS data set using some or all of the variables.

Syntax

PROC PRINT <option(s)>;

Summary of Optional Arguments

specifies text for the links in the HTML contents file.
specifies the SAS data set to print.
Control column format
controls the orientation of the column headings.
specifies to use the variables' labels as column headings.
specifies the split character, which controls line breaks in column headings.
specify one or more style elements for the Output Delivery System to use for different parts of the report.
displays the BY variable label on the summary line in place of the BY variable name.
Control general format
writes a blank line after n observations.
writes a blank line between observations.
prints the number of observations in the data set, in BY groups, or both and specifies explanatory text to print with the number.
suppress the column in the output that identifies each observation by number.
specifies a column heading for the column that identifies each observation by number.
rounds unformatted numeric values to two decimal places.
Control page format
formats the rows on a page.
specifies to use each variable's formatted width as its column width on all pages.
determines the column width for each variable.

Optional Arguments

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 to 0 at the beginning of each BY group for all ODS destinations.
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.
CONTENTS=link-text
specifies the text for the links in the HTML contents file to the output produced by the PROC PRINT statement.
Restrictions:CONTENTS= does not affect the HTML body file. It affects only the HTML contents file.

CONTENTS= is not valid for the ODS LISTING destination.

See:For information about HTML output, see Files Produced by the HTML Destination and ODS HTML Statement in SAS Output Delivery System: User's Guide.
DATA=SAS-data-set
specifies the SAS data set to print.
DOUBLE
writes a blank line between observations.
Alias:D
Restriction:DOUBLE is valid only for the ODS LISTING destination.
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
Restriction:For Listing output, if the column heading is too long for the page, the variable name is used in place of a label.
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
specifies to use the variables' labels as column headings.
Alias:L
Default:PROC PRINT uses the name of the variable as the column heading in the following circumstances:
if you omit the LABEL option in the PROC PRINT statement, even if the PROC PRINT step contains a LABEL statement
if a variable does not have a label
Interactions: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.)

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=.

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 System Options: Reference.
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:For information about 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 Statements: Reference.

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.
NOOBS
suppress the column in the output that identifies each observation by number.
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 the SPLIT= option.)
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 following is true:
  • 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 that are 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.
ROWS=page-format
formats the 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:ROWS= is valid only for the ODS LISTING destination. Therefore, HTML output from PROC PRINT appears the same if 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:Page Layout for discussion of the default layout.
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=
Interactions:You do not need to use both LABEL and SPLIT= because SPLIT= implies the use of labels.

The OBS= option honors the split character. (See the discussion of OBS=“column-header”.)

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.
STYLE <(locations(s))>=<style-element-name> <[style-attribute-specification(s)]>
specify one or more style elements for the Output Delivery System to use for different parts of the report. You can use braces ({ and }) instead of square brackets ([ and ]).
location
identifies the part of the report that the STYLE option affects. If location(s) is not specified, PROC PRINT determines the location to where the style is applied based on the statement, the specified style element, and the style attribute.
The following table shows the available locations and the other statements in which you can specify them.
Specifying Locations in the STYLE Option
Location
Affected Report Part
Can Also Be Used in These Statements
BYLABEL
Label for the BY variable on the line containing the SUM totals
None
DATA
Cells of all columns
VAR
ID
SUM
GRANDTOTAL
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
Data in the OBS column
None
OBSHEADER
Header of the OBS column
None
TABLE
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
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
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).
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 the TEMPLATE procedure. See SAS Output Delivery System: User's Guide.
When style elements are processed, more specific style elements override less specific style elements. 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= 1
BACKGROUNDIMAGE=
COLOR= 1
BORDERCOLOR=
FRAME=
BORDERCOLORDARK=
HTMLCLASS=
BORDERCOLORLIGHT=
TEXTALIGN=
BORDERWIDTH=
OUTPUTWIDTH=
CELLPADDING=
POSTHTML=
CELLSPACING=
POSTIMAGE=
FONT= 1
POSTTEXT=
FONTFAMILY= 1
PREHTML=
FONTSIZE= 1
PREIMAGE=
FONTSTYLE= 1
PRETEXT=
FONTWEIGHT= 1
RULES=
1When 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=
Restrictions:This option affects all destinations except Listing and Output.

STYLE= is not valid for the ODS LISTING destination

See:For information about style attributes, see DEFINE Style Statement in SAS Output Delivery System: User's Guide.
SUMLABEL
displays the BY variable label on 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.
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 System Options: Reference.
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
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.
Tips: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.

WIDTH=UNIFORM is the same as UNIFORM.

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.
Restriction:WIDTH= is valid only for the LISTING destination.
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:For a discussion of default column widths, see Column Width.