Report writing is simplified if you approach it with a clear understanding of what you want the report to look like. The most important thing to figure out is the layout of the report. To determine the layout, ask yourself the following kinds of questions:
Once you understand the layout of the report, use the COLUMN and DEFINE statements in PROC REPORT to construct the layout. The COLUMN statement lists the items that appear in the columns of the report, describes the arrangement of the columns, and defines headers that span multiple columns. A report item can be
Omit the COLUMN statement if you want to include all variables in the input data set in the same order as they occur in the data set. Note: If you start PROC REPORT in the windowing environment without the COLUMN statement, the initial report includes only as many variables as will fit on one page. The DEFINE statement (or, in the windowing environment, the DEFINITION window) defines the characteristics of an item in the report. These characteristics include how PROC REPORT uses the item in the report, the text of the column header, and the format to use to display values. Usage of Variables in a ReportMuch of a report's layout is determined by the usages that you specify for variables in the DEFINE statements or DEFINITION windows. For data set variables, these usages are
A report can contain variables that are not in the input data set. These variables must have a usage of COMPUTED. Display VariablesA report that contains one or more display variables has a row for every observation in the input data set. Display variables do not affect the order of the rows in the report. If no order variables appear to the left of a display variable, the order of the rows in the report reflects the order of the observations in the data set. By default, PROC REPORT treats all character variables as display variables.Order VariablesA report that contains one or more order variables has a row for every observation in the input data set. If no display variable appears to the left of an order variable, PROC REPORT orders the detail rows according to the ascending, formatted values of the order variable. You can change the default order with ORDER= and DESCENDING in the DEFINE statement or with the DEFINITION window.If the report contains multiple order variables, PROC REPORT establishes the order of the detail rows by sorting these variables from left to right in the report. PROC REPORT does not repeat the value of an order variable from one row to the next if the value does not change. Across VariablesPROC REPORT creates a column for each value of an across variable. PROC REPORT orders the columns by the ascending, formatted values of the across variable. You can change the default order with ORDER= and DESCENDING in the DEFINE statement or with the DEFINITION window. If no other variable helps define the column (see COLUMN Statement ), PROC REPORT displays the N statistic (the number of observations in the input data set that belong to that cell of the report).If you are familiar with procedures that use class variables, you will see that across variables are class variables that are used in the column dimension. Group VariablesIf a report contains one or more group variables, PROC REPORT tries to consolidate into one row all observations from the data set that have a unique combination of formatted values for all group variables.When PROC REPORT creates groups, it orders the detail rows by the ascending, formatted values of the group variable. You can change the default order with ORDER= and DESCENDING in the DEFINE statement or with the DEFINITION window. If the report contains multiple group variables, the REPORT procedure establishes the order of the detail rows by sorting these variables from left to right in the report. PROC REPORT does not repeat the values of a group variable from one row to the next if the value does not change. If you are familiar with procedures that use class variables, you will see that group variables are class variables that are used in the row dimension. Note: You cannot always create groups. PROC REPORT cannot consolidate observations into groups if the report contains any order variables or any display variables that do not have one or more statistics associated with them (see COLUMN Statement ). In the windowing environment, if PROC REPORT cannot immediately create groups, it changes all display and order variables to group variables so that it can create the group variable that you requested. In the nonwindowing environment, it returns to the SAS log a message that explains why it could not create groups. Instead, it creates a detail report that displays group variables the same way as it displays order variables. Even if PROC REPORT creates a detail report, the variables that you defined as group variables retain that usage in their definitions. Analysis VariablesAn analysis variable is a numeric variable that is used to calculate a statistic for all the observations represented by a cell of the report. (Across variables, in combination with group variables or order variables, determine which observations a cell represents.) You associate a statistic with an analysis variable in the variable's definition or in the COLUMN statement. By default, PROC REPORT uses numeric variables as analysis variables that are used to calculate the Sum statistic.The value of an analysis variable depends on where it appears in the report:
Computed VariablesComputed variables are variables that you define for the report. They are not in the input data set, and PROC REPORT does not add them to the input data set. However, computed variables are included in an output data set if you create one.In the windowing environment, you add a computed variable to a report from the COMPUTED VAR window. In the nonwindowing environment, you add a computed variable by
Interactions of Position and UsageThe position and usage of each variable in the report determine the report's structure and content. PROC REPORT orders the detail rows of the report according to the values of order and group variables, considered from left to right in the report. Similarly, PROC REPORT orders columns for an across variable from top to bottom, according to the values of the variable.Several items can collectively define the contents of a column in a report. For instance, in Stacking Department and Sales , the values that appear in the third and fourth columns are collectively determined by Sales, an analysis variable, and by Department, an across variable. You create this kind of report with the COLUMN statement or, in the windowing environment, by placing report items above or below each other. This is called stacking items in the report because each item generates a header, and the headers are stacked one above the other. Stacking Department and
Sales When you use multiple items to define the contents of a column, at most one of the following can be in a column:
More than one of these items in a column creates a conflict for PROC REPORT about which values to display. Report Items That Can Share Columns shows which report items can share a column. Note: You cannot stack group or order variables with other report items. Report Items That Can Share Columns
The following items can stand alone in a column:
Note: The values in a column occupied only by an across variable are frequency counts. Statistics Available in PROC REPORT
Every statistic except N must be associated with a variable. You associate a statistic with a variable either by placing the statistic above or below a numeric display variable or by specifying the statistic as a usage option in the DEFINE statement or in the DEFINITION window for an analysis variable. You can place N anywhere because it is the number of observations in the input data set that contributes to the value in a cell of the report. The value of N does not depend on a particular variable. For definitions of these statistics, see Keywords and Formulas . Note: If you use the MISSING option in the PROC REPORT statement, N includes observations with missing group, order, or across variables. A compute block is one or more programming statements that appear either between a COMPUTE and an ENDCOMP statement or in a COMPUTE window. PROC REPORT executes these statements as it builds the report. A compute block can be associated with a report item (a data set variable, a statistic, or a computed variable) or with a location (at the top or bottom of the report; 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 in the report (see Using Break Lines ). Note: When you use the COMPUTE statement, you do not have to use a corresponding BREAK or RBREAK statement. (See Ordering the Rows in a Report , which uses COMPUTE AFTER but does not use the RBREAK statement). Use these statements only when you want to implement one or more BREAK statement or RBREAK statement options (see Writing a Customized Summary on Each Page , which uses both COMPUTE AFTER MANAGER and BREAK AFTER MANAGER. The Purpose of Compute BlocksA compute block that is associated with a report item can
A compute block that is associated with a location can write a customized summary. In addition, all compute blocks can use SAS
language elements to perform calculations (see The Contents of Compute Blocks ). A PROC REPORT step can contain multiple compute blocks. The Contents of Compute BlocksIn the windowing environment, a compute block is in a COMPUTE window. In the nonwindowing environment, a compute block begins with a COMPUTE statement and ends with an ENDCOMP statement. Within a compute block, you can use these SAS language elements:
For information about SAS language elements see the appropriate section in SAS Language Reference: Dictionary. Within a compute block, you can also use these PROC REPORT features:
Four Ways to Reference Report Items in a Compute BlockA compute block can reference any report item that forms a column in the report (whether or not the column is visible). You reference report items in a compute block in one of four ways:
The following table shows how to use each type of reference in a compute block.
Compute Block ProcessingPROC REPORT processes compute blocks in two different ways.
Note: PROC REPORT recalculates computed variables at breaks. For details on compute block processing see How PROC REPORT Builds a Report . Break lines are lines of text (including blanks) that appear at particular locations, called breaks, in a report. A report can contain multiple breaks. Generally, break lines are used to visually separate parts of a report, to summarize information, or both. They can occur
Break lines can contain
Creating Break LinesThere are two ways to create break lines. The first way is simpler. It produces a default summary. The second way is more flexible. It produces a customized summary and provides a way to slightly modify a default summary. Default summaries and customized summaries can appear at the same location in a report.Default summaries are produced with the BREAK statement, the RBREAK statement, or the BREAK window. You can use default summaries to visually separate parts of the report, to summarize information for numeric variables, or both. Options provide some control over the appearance of the break lines, but if you choose to summarize numeric variables, you have no control over the content and the placement of the summary information. (A break line that summarizes information is a summary line.) Customized summaries are produced in
a compute block. You can control both the appearance and content of a customized summary, but you must write the code to do so. Order of Break LinesYou control the order of the lines in a customized summary. However, PROC REPORT controls the order of lines in a default summary and the placement of a customized summary relative to a default summary. When a default summary contains multiple break lines, the order in which the break lines appear is
If you define a customized summary for the same location, customized break lines appear after underlining or double underlining. The Automatic Variable _BREAK_PROC REPORT automatically creates a variable called _BREAK_. This variable contains
You specify style elements for PROC REPORT with the STYLE= option. Using the STYLE= Option in PROC REPORT shows where you can use this option. Specifications on a statement other than the PROC REPORT statement override the same specification in the PROC REPORT statement. However, any style attributes that you specify in the PROC REPORT statement and do not override in another statement are inherited. For instance, if you specify a blue background and a white foreground for all column headers in the PROC REPORT statement, and you specify a gray background for the column headers of a variable in the DEFINE statement, the background for that particular column header is gray, and the foreground is white (as specified in the PROC REPORT statement). Detailed information about STYLE= is provided in the documentation for individual statements. Using the STYLE= Option in PROC REPORT
Printing from the REPORT WindowBy default, if you print from the REPORT window, the report is routed directly to your printer. If you want, you can specify a form to use for printing (see Printing with a Form ). Forms specify things like the type of printer that you are using, text format, and page orientation.Note: Forms are available only when you run SAS from a windowing environment. Operating Environment Information: Printing is implemented differently in different operating environments. For information related to printing, consult SAS Language Reference: Concepts. Additional information may be available in the SAS documentation for your operating environment. Printing with a FormTo print with a form from the REPORT window:
Printing from the OUTPUT WindowIf you are running PROC REPORT with the NOWINDOWS option, the default destination for the output is the OUTPUT window. Use the commands in the File pull-down menu to print the report.Printing from Noninteractive or Batch ModeIf you use noninteractive or batch mode, SAS writes the output either to the display or to external files, depending on the operating environment and on the SAS options that you use. Refer to the SAS documentation for your operating environment for information about how these files are named and where they are stored.You can print the output file directly or use PROC PRINTTO to redirect the output to another file. In either case, no form is used, but carriage control characters are written if the destination is a print file. Use operating environment commands to send the
file to the printer. Printing from Interactive Line ModeIf you use interactive line mode, by default the output and log are displayed on the screen immediately following the programming statements. Use PROC PRINTTO to redirect the output to an external file. Then use operating environment commands to send the file to the printer.Using PROC PRINTTOPROC PRINTTO defines destinations for the SAS output and the SAS log (see The PRINTTO Procedure ).PROC PRINTTO does not use a form, but it does write carriage control characters if you are writing to a print file. CAUTION:You need two PROC PRINTTO steps. The first PROC PRINTTO step precedes the PROC REPORT step. It redirects the output to a file. The second PROC PRINTTO step follows the PROC REPORT step. It reestablishes the default destination and frees the output file. You cannot print the file until PROC PRINTTO frees it.In the windowing environment, you can save the definition of the current report by selecting
You can use a report definition to create an identically structured report for any SAS data set that contains variables with the same names as the ones used in the report definition. Use the REPORT= option in the PROC REPORT statement to load a report definition when you start PROC REPORT. In the windowing environment, load a report definition from the LOAD REPORT window by selecting
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved. What is an association between tables where both tables contain a common field?A table relationship works by matching data in key fields — often a field with the same name in both tables. In most cases, these matching fields are the primary key from one table, which provides a unique identifier for each record, and a foreign key in the other table.
Which of the following functions is the default summary statistic for Pivottables?When you add a numerical field to the pivot table's Values area, Sum will be the default summary function. (Note: If the field contains text or blank cells, Count will be the default.)
What is the process of analyzing large amounts of data to identify trends and patterns in the data?Big data analytics describes the process of uncovering trends, patterns, and correlations in large amounts of raw data to help make data-informed decisions. These processes use familiar statistical analysis techniques—like clustering and regression—and apply them to more extensive datasets with the help of newer tools.
Which is not true of filters in PivotTable?Which is not true of filters in a PivotTable? Summary statistics do not change to reflect the values selected in the slicer.
|