O'Reilly logo

Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating More Sophisticated Reports
Adjusting the Column Layout
Understanding Column Width and Spacing for ODS LISTING Output
If you are working with the ODS LISTING destination, you can modify the column
spacing (SPACING=) and the column width (COLWIDTH=) by specifying options in
either the PROC REPORT statement or the DEFINE statement.
To control the spacing between columns, you can use the SPACING= option in the
following statements:
PROC REPORT statement to specify the default number of blank characters between
all columns
DEFINE statement to override the default value and to specify the number of blank
characters to the left of a particular column
In the LISTING Output, PROC REPORT inserts two blank spaces between the columns.
To remove space between columns, specify SPACING=0. The maximum space that
PROC REPORT allows between columns depends on the number of columns in the
report. The sum of all column widths plus the blank characters to left of each column
cannot exceed the line size.
To specify the column widths, you can use the following options:
the COLWIDTH= option in the PROC REPORT statement to specify the default
number of characters for columns that contain computed variables or numeric data
set variables
the WIDTH= option in the DEFINE statement to specify the width of the column
that PROC REPORT uses to display a report item
By default, the column width is nine characters for numeric values. You can specify the
column width as small as one character and as large as the line size. PROC REPORT
sets the width of a column by first looking at the WIDTH= option in the DEFINE
statement. If you omit WIDTH=, then PROC REPORT uses a column width large
enough to accommodate the format for a report item. If you do not assign a format, then
the column width is either the length of the character variable or the value of the
COLWIDTH= option.
You can adjust the column layout by specifying how to align the formatted values of a
report item and the column heading with the column width. The following options in the
DEFINE statement align the columns:
CENTER
centers the column values and column heading.
LEFT
left-aligns the column values and column heading
RIGHT
right-aligns the column values and column heading.
514 Chapter 29 Creating Detail and Summary Reports with the REPORT Procedure
Modifying the Column Width and Spacing
The following program modifies column spacing in a summary report that shows the
total yearly sales for each sales representative:
options linesize=80 pageno=1 nodate;
proc report data=year_sales spacing=3;
column SalesRep Units AmountSold;
define SalesRep /group right;
define Units / analysis sum width=5;
define AmountSold/ analysis sum width=10;
title1 'TruBlend Coffee Makers Sales Report';
title2 'Total Yearly Sales';
run;
The following list corresponds to the numbered items in the preceding program:
The SPACING= option in the PROC REPORT statement inserts three blank
characters between all the columns.
The RIGHT option in the DEFINE statement right-aligns the name of the sales
representative and the column heading in the column.
The WIDTH= options in the DEFINE statements specify enough space to
accommodate column headings on one line.
The following output displays the report:
Output 29.7 Adjusting Column Width and Spacing for LISTING Output
TruBlend Coffee Makers Sales Report 1
Total Yearly Sales
SalesRep Units AmountSold
Garcia 15969 512070.78
Hollingsworth 10620 347246.1
Jensen 14400 461162.6
The column width for SalesRep is 14 characters wide, which is the length of the
variable.
Customizing Column Headings
Understanding the Structure of Column Headings
In ODS LISTING output, PROC REPORT does not insert a vertical space beneath
column headings to visually separate the detail rows from the headers. To improve the
appearance of a report generated using the ODS LISTING destination, you can underline
the column headings, insert a blank line beneath column headings, and specify your own
column headings. The HEADLINE and HEADSKIP options in the PROC REPORT
statement enable you to underline the column headings and insert a blank line after the
column headings, respectively.
By default, SAS uses the variable name or the variable label, if the data set variable was
previously assigned a label, for the column heading. To specify a different column
heading, place text between single or double quotation marks in the DEFINE statement
for the report item.
Creating More Sophisticated Reports 515

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required