Chapter Contents

Previous

Next
The REPORT Procedure

COMPUTE Statement


Starts a compute block. A compute block contains one or more programming statements that PROC REPORT executes as it builds the report.

Interaction: An ENDCOMP statement must mark the end of the group of statements in the compute block.
Featured in: Ordering the Rows in a Report , Using Aliases to Obtain Multiple Statistics for the Same Variable , Consolidating Multiple Observations into One Row of a Report , Creating a Column for Each Value of a Variable , Writing a Customized Summary on Each Page , and Calculating Percentages


COMPUTE location <target>
</ STYLE=<style-element-name>
<[style-attribute-specification(s)]>>;
LINE specification(s);
. . . select SAS language elements . . .
ENDCOMP;
COMPUTE report-item </ type-specification>;
CALL DEFINE (column-id, 'attribute-name', value);
. . . select SAS language elements . . .
ENDCOMP;

A compute block can be associated with a report item or with a location (at the top or bottom of a report; at the top or bottom of a page; before or after a set of observations). You create a compute block with the COMPUTE window or with the COMPUTE statement. One form of the COMPUTE statement associates the compute block with a report item. Another form associates the compute block with a location.

For a list of the SAS language elements that you can use in compute blocks, see The Contents of Compute Blocks .


Required Arguments
You must specify either a location or a report item in the COMPUTE statement.

location
determines where the compute block executes in relation to target.

AFTER
executes the compute block at a break in one of the following places:

  • immediately after the last row of a set of rows that have the same value for the variable that you specify as target or, if there is a default summary on that variable, immediately after the creation of the preliminary summary line (see How PROC REPORT Builds a Report ).

  • near the bottom of each page, immediately before any footnotes, if you specify _PAGE_ as target

  • at the end of the report if you omit a target.

BEFORE
executes the compute block at a break in one of the following places:

  • immediately before the first row of a set of rows that have the same value for the variable that you specify as target or, if there is a default summary on that variable, immediately after the creation of the preliminary summary line (see How PROC REPORT Builds a Report ).

  • near the top of each page, between any titles and the column headers, if you specify _PAGE_ as target

  • immediately before the first detail row if you omit a target.

Featured in: Using Aliases to Obtain Multiple Statistics for the Same Variable and Writing a Customized Summary on Each Page

report-item
specifies a data set variable, a computed variable, or a statistic to associate the compute block with. If you are working in the nonwindowing environment, you must include the report item in the COLUMN statement. If the item is a computed variable, you must include a DEFINE statement for it.
Featured in: Consolidating Multiple Observations into One Row of a Report and Creating a Column for Each Value of a Variable

CAUTION:
The position of a computed variable is important. PROC REPORT assigns values to the columns in a row of a report from left to right. Consequently, you cannot base the calculation of a computed variable on any variable that appears to its right in the report.  [cautionend]


Options

STYLE=<style-element-name><[style-attribute-specification(s)]>
specifies the style to use for the text that is created by any LINE statements in this compute block.

Note:   You can use braces ({ and }) instead of square brackets ([ and ]).  [cautionend]

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 Institute provides some style definitions. Users can create their own style definitions and style elements with PROC TEMPLATE.
Default: If you do not specify a style element, PROC REPORT uses NoteContent.
See also: For information about Institute-supplied style definitions, see What Style Definitions Are Shipped with the Software? .

For information about PROC TEMPLATE and the Output Delivery System, see The Complete Guide to the SAS Output Delivery System.

style-attribute-specification
describes one or more style attributes to change. Each style-attribute-specification has this general form:
style-attribute-name=style-attribute-value

You can set the following style attributes in the STYLE= option in the COMPUTE statement:

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=

Retriction: This option affects only the HTML and Printer output.
Featured in: Specifying Style Elements for HTML Output in Multiple Statements

target
controls when the compute block executes. If you specify a location (BEFORE or AFTER) for the COMPUTE statement, you can also specify target, which can be one of the following:

break-variable
is a group or order variable.

When you specify a break variable, PROC REPORT executes the statements in the compute block each time the value of the break variable changes.

_PAGE_ </ justification>
causes the compute block to execute once for each page, either immediately after printing any titles or immediately before printing any footnotes. justification controls the placement of text and values. It can be one of the following:
CENTER centers each line that the compute block writes.
LEFT left-justifies each line that the compute block writes.
RIGHT right-justifies each line that the compute block writes.
Default: CENTER

Featured in: Writing a Customized Summary on Each Page

type-specification
specifies the type and, optionally, the length of report-item. If the report item associated with a compute block is a computed variable, PROC REPORT assumes that it is a numeric variable unless you use a type specification to specify that it is a character variable. A type specification has the form
CHARACTER <LENGTH=length>

where

CHARACTER
specifies that the computed variable is a character variable. If you do not specify a length, the variable's length is 8.
Alias: CHAR
Featured in: Calculating Percentages

LENGTH=length
specifies the length of a computed character variable.
Default: 8
Range: 1 to 200
Interaction: If you specify a length, you must use CHARACTER to indicate that the computed variable is a character variable.
Featured in: Calculating Percentages


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.