Syntax: PRINT Procedure


Tip: Supports the Output Delivery System. See Output Delivery System on page 32 for details.

ODS Table Name : Print

Reminder: You can use the ATTRIB, FORMAT, LABEL, and WHERE statements. See Chapter 3, Statements with the Same Function in Multiple Procedures, on page 57 for details. You can also use any global statements. See Global Statements on page 18 for a list.

PROC PRINT < option(s) >;

  • BY <DESCENDING> variable-1 < <DESCENDING> variable-n >

      • <NOTSORTED>;

    • PAGEBY BY-variable ;

    • SUMBY BY-variable ;

  • ID variable(s) < option >;

  • SUM variable(s) < option >;

  • VAR variable(s) < option >;

To do this

Use this statement

Produce a separate section of the report for each BY group

BY

Identify observations by the formatted values of the variables that you list instead of by observation numbers

ID

Control page ejects that occur before a page is full

PAGEBY

Limit the number of sums that appear in the report

SUMBY

Total values of numeric variables

SUM

Select variables that appear in the report and determine their order

VAR

PROC PRINT Statement

PROC PRINT < option(s) >;

To do this

Use this 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 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 header 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

 

Determine the column width for each variable

WIDTH=

Options

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 on HTML output, see The Complete Guide to the SAS Output Delivery System .

  • 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 on page 19

DOUBLE

  • writes a blank line between observations.

  • Alias: D

  • Restriction: This option has no effect on the HTML output.

  • Featured in: Example 1 on page 739

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 dictates 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 may 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 header 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 Chapter 3, Statements with the Same Function in Multiple Procedures, on page 57.

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

  • Featured in: Example 3 on page 747

    Note: The SAS system option LABEL must be in effect in order for any procedure to use labels. For more information see the section on system options in SAS Language Reference: Dictionary

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.

    If you use the N option

    PROC PRINT

    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: Example 2 on page 743 (alone)

    • Example 3 on page 747 (with a BY statement)

    • Example 4 on page 753 (with a BY statement and a SUM statement)

NOOBS

  • suppresses the observation number in the output.

  • Featured in: Example 3 on page 747

OBS= column-header

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

  • Tip: OBS= honors the split character (see the discussion of SPLIT= on page 726 ).

  • Featured in: Example 2 on page 743

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

    start figure
     PROC PRINT without                 PROC PRINT with    Actual Values       the ROUND option                   the ROUND option                  PROC MEANS ============================================================================================================                                                                                                         OBS               X           OBS               X         Analysis Variable : X                                                                                     .003                 1             0.00            1             0.00                  Sum    .004                 2             0.00            2             0.00        -------------    .009                 3             0.01            3             0.01            0.0160000   =====                              =====                         =====        -------------    .016                               0.02                          0.01                                                                                           ============================================================================================================ 
    end figure

    Figure 35.1: 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 may lead to unexpected results.

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 or not 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 on page 736 for discussion of the default layout.

  • Featured in: Example 7 on page 769

SPLIT= split-character

  • specifies the split character, which controls line breaks in column headers. It also uses labels as column headers. 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= on page 725.)

  • Featured in: Example 2 on page 743

    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

<( location(s) )>=< style-element-name ><[ style-attribute-specification(s) ]> specifies the style element to use for the specified locations in the report.

    • Note: 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 instance, if you specify a blue background and a white foreground for all column headers in the PROC PRINT statement, and you specify a gray background for the column headers of a variable in the VAR statement, the background for that particular column header is gray, and the foreground is white (as specified in the PROC PRINT statement).

Table 35.1: Specifying Locations in the STYLE Option

This location

Affects this part of the report

And can also be specified for individual items in this statement

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 headers

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.

Table 35.2: 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.

Table 35.3: 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:

BACKGROUND=

FONT_WIDTH= [*]

BACKGROUNDIMAGE=

FOREGROUND= [*]

BORDERCOLOR=

FRAME=

BORDERCOLORDARK=

HTMLCLASS=

BORDERCOLORLIGHT=

JUST=

BORDERWIDTH=

OUTPUTWIDTH=

CELLPADDING =

POSTHTML=

CELLSPACING=

POSTIMAGE=

FONT= [*]

POSTTEXT=

FONT_FACE= [*]

PREHTML=

FONT_SIZE= [*]

PREIMAGE=

FONT_STYLE= [*]

PRETEXT=

FONT_WEIGHT= [*]

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.

[*] 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.

[*] 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.

[*] 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.

[*] 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.

[*] 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.

[*] 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=

FONT_WIDTH=

BACKGROUND=

HREFTARGET=

BACKGROUNDIMAGE=

HTMLCLASS=

BORDERCOLOR=

JUST=

BORDERCOLORDARK=

NOBREAKSPACE=

BORDERCOLORLIGHT=

POSTHTML=

BORDERWIDTH=

POSTIMAGE=

CELLHEIGHT=

POSTTEXT=

CELLWIDTH=

PREHTML=

FLYOVER=

PREIMAGE=

FONT=

PRETEXT=

FONT_FACE=

PROTECTSPECIALCHARS=

FONT_SIZE=

TAGATTR=

FONT_STYLE=

URL=

FONT_WEIGHT=

VJUST=

  • For information about style attributes, see DEFINE STYLE statement in The Complete Guide to the SAS Output Delivery System .

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

UNIFORM

  • See WIDTH=UNIFORM on page 730.

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 may 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 may lessen the usefulness of WIDTH=.

  • See also: For a discussion of default column widths, see Column Width on page 738 .

BY Statement

Produces a separate section of the report for each BY group.

Main discussion: BY on page 58

Featured in: Example 3 on page 747, Example 4 on page 753, Example 5 on page 758, Example 6 on page 764, and Example 8 on page 776

BY <DESCENDING> variable-1

    • < <DESCENDING> variable-n >

  • <NOTSORTED>;

Required Arguments

variable

  • specifies the variable that the procedure uses to form BY groups. You can specify more than one variable. If you do not use the NOTSORTED option in the BY statement, the observations in the data set must either be sorted by all the variables that you specify, or they must be indexed appropriately. Variables in a BY statement are called BY variables .

Options

DESCENDING

  • specifies that the data set is sorted in descending order by the variable that immediately follows the word DESCENDING in the BY statement.

NOTSORTED

  • specifies that observations are not necessarily sorted in alphabetic or numeric order. The data are grouped in another way, such as chronological order.

    The requirement for ordering or indexing observations according to the values of BY variables is suspended for BY-group processing when you use the NOTSORTED option. In fact, the procedure does not use an index if you specify NOTSORTED. The procedure defines a BY group as a set of contiguous observations that have the same values for all BY variables. If observations with the same values for the BY variables are not contiguous, the procedure treats each contiguous set as a separate BY group.

Using the BY Statement with an ID Statement

PROC PRINT uses a special layout if all BY variables appear in the same order at the beginning of the ID statement. (See Example 8 on page 776.)

Using the BY Statement with the NOBYLINE Option

If you use the BY statement with the SAS system option NOBYLINE, which suppresses the BY line that normally appears in output produced with BY-group processing, PROC PRINT always starts a new page for each BY group. This behavior ensures that if you create customized BY lines by putting BY-group information in the title and suppressing the default BY lines with NOBYLINE, the information in the titles matches the report on the pages.

ID Statement

Identifies observations by using the formatted values of the variables that you list instead of by using observation numbers.

Featured in: Example 7 on page 769 and Example 8 on page 776

ID variable(s) </ STYLE <( location(s) )>

  • =< style-element-name ><[ style-attribute-specification(s) ]>>;

Required Arguments

variable(s)

  • specifies one or more variables to print instead of the observation number at the beginning of each row of the report.

  • Restriction: If the ID variables occupy so much space that no room remains on the line for at least one other variable, PROC PRINT writes a warning to the SAS log and does not treat all ID variables as ID variables.

  • Interaction: If a variable in the ID statement also appears in the VAR statement, the output contains two columns for that variable.

Options

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

  • specifies the style element to use for ID columns created with the ID statement. For information about the arguments of this option and how it is used, see STYLE on page 727 in the PROC PRINT statement.

  • Tip: To specify different style elements for different ID columns, use a separate ID statement for each variable and add a different STYLE option to each ID statement.

Using the BY Statement with an ID Statement

PROC PRINT uses a special layout if all BY variables appear in the same order at the beginning of the ID statement. (See Example 8 on page 776.)

PAGEBY Statement

Controls page ejects that occur before a page is full.

Requirements: BY statement

Featured in: Example 3 on page 747

PAGEBY BY-variable ;

Required Arguments

BY-variable

  • identifies a variable appearing in the BY statement in the PROC PRINT step. If the value of the BY variable changes, or if the value of any BY variable that precedes it in the BY statement changes, PROC PRINT begins printing a new page.

  • Interaction: If you use the BY statement with the SAS system option NOBYLINE, which suppresses the BY line that normally appears in output produced with BY-group processing, PROC PRINT always starts a new page for each BY group.

  • This behavior ensures that if you create customized BY lines by putting BY-group information in the title and suppressing the default BY lines with NOBYLINE, the information in the titles matches the report on the pages. (See Creating Titles That Contain BY-Group Information on page 20.)

SUM Statement

Totals values of numeric variables.

Featured in: Example 4 on page 753, Example 5 on page 758, Example 6 on page 764, and Example 8 on page 776

SUM variable(s) </ STYLE <( location(s) )>

  • =< style-element-name ><[ style-attribute-specification(s) ]>>;

Required Arguments

variable(s)

  • identifies the numeric variables to total in the report.

Option

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

  • specifies the style element to use for cells containing sums that are created with the SUM statement. For information about the arguments of this option and how it is used, see STYLE on page 727 in the PROC PRINT statement.

  • Tip: To specify different style elements for different cells reporting sums, use a separate SUM statement for each variable and add a different STYLE option to each SUM statement.

  • Tip: If the STYLE option is used in multiple SUM statements that affect the same location, the STYLE option in the last SUM statement will be used.

Using the SUM and BY Statements Together

When you use a SUM statement and a BY statement with one BY variable, PROC PRINT sums the SUM variables for each BY group that contains more than one observation and totals them over all BY groups (see Example 4 on page 753).

When you use a SUM statement and a BY statement with multiple BY variables, PROC PRINT sums the SUM variables for each BY group that contains more than one observation, just as it does if you use only one BY variable. However, it provides sums only for those BY variables whose values change when the BY group changes. (See Example 5 on page 758.)

Note: When the value of a BY variable changes, the SAS System considers that the values of all variables listed after it in the BY statement also change.

SUMBY Statement

Limits the number of sums that appear in the report.

Requirements: BY statement

Featured in: Example 6 on page 764

SUMBY BY-variable ;

Required Arguments

BY-variable

  • identifies a variable that appears in the BY statement in the PROC PRINT step. If the value of the BY variable changes, or if the value of any BY variable that precedes it in the BY statement changes, PROC PRINT prints the sums of all variables listed in the SUM statement.

What Variables Are Summed?

If you use a SUM statement, PROC PRINT subtotals only the SUM variables. Otherwise, PROC PRINT subtotals all the numeric variables in the data set except those listed in the ID and BY statements.

VAR Statement

Selects variables that appear in the report and determines their order.

Tip: If you omit the VAR statement, PROC PRINT prints all variables in the data set.

Featured in: Example 1 on page 739 and Example 8 on page 776

VAR variable(s) </ STYLE <( location(s) )>

  • =< style-element-name ><[ style-attribute-specification(s) ]>>;

Required Arguments

variable(s)

  • identifies the variables to print. PROC PRINT prints the variables in the order that you list them.

  • Interaction: In the PROC PRINT output, variables that are listed in the ID statement precede variables that are listed in the VAR statement. If a variable in the ID statement also appears in the VAR statement, the output contains two columns for that variable.

Option

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

  • specifies the style element to use for all columns that are created by a VAR statement. For information about the arguments of this option and how it is used, see STYLE on page 727 in the PROC PRINT statement.

  • Tip: To specify different style elements for different columns, use a separate VAR statement to create a column for each variable and add a different STYLE option to each VAR statement.




Base SAS 9.1.3 Procedures Guide (Vol. 1)
Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
ISBN: 1590472047
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net