REPORT Procedure

Example 12: Creating and Processing an Output Data Set

Features:
PROC REPORT statement options:
BOX
OUT=
DEFINE statement options:
ANALYSIS
GROUP
NOPRINT
SUM
Other features:

Data set options: WHERE=

Data set: GROCERY
Format: $MGRFMT

Details

This example uses WHERE processing as it builds an output data set. This technique enables you to do WHERE processing after you have consolidated multiple observations into a single row.
The first PROC REPORT step creates a report (which it does not display) in which each row represents all the observations from the input data set for a single manager. The second PROC REPORT step builds a report from the output data set. This report uses line-drawing characters to separate the rows and columns.

Program to Create Output Data Set

libname proclib
'SAS-library';
options fmtsearch=(proclib);
proc report data=grocery nowd
            out=temp( where=(sales gt 1000) );
   column manager sales;
   define manager / group noprint;
   define sales / analysis sum noprint;
run;

Program Description

Declare the PROCLIB library. The PROCLIB library is used to store user-created formats.
libname proclib
'SAS-library';
Specify the format search library.The SAS system option FMTSEARCH= adds the SAS library PROCLIB to the search path that is used to locate formats.
options fmtsearch=(proclib);
Specify the report options and columns. The NOWD option runs PROC REPORT without the REPORT window and sends its output to the open output destinations. OUT= creates the output data set TEMP. The output data set contains a variable for each column in the report (Manager and Sales) as well as for the variable _BREAK_, which is not used in this example. Each observation in the data set represents a row of the report. Because Manager is a group variable and Sales is an analysis variable that is used to calculate the Sum statistic, each row in the report (and therefore each observation in the output data set) represents multiple observations from the input data set. In particular, each value of Sales in the output data set is the total of all values of Sales for that manager. The WHERE= data set option in the OUT= option filters those rows as PROC REPORT creates the output data set. Only those observations with sales that exceed $1,000 become observations in the output data set.
proc report data=grocery nowd
            out=temp( where=(sales gt 1000) );
   column manager sales;
Define the group and analysis variables. Because the definitions of all report items in this report include the NOPRINT option, PROC REPORT does not print a report. However, the PROC REPORT step does execute and create an output data set.
   define manager / group noprint;
   define sales / analysis sum noprint;
run;

Output Showing the Output Data Set

The following output is the output data set that PROC REPORT creates. It is used as the input set in the second PROC REPORT step.
Work.Temp Data Set

Program That Uses the Output Data Set

proc report data=temp box nowd;
   column manager sales;
   define manager / group format=$mgrfmt.;
   define sales / analysis sum format=dollar11.2;
   title 'Managers with Daily Sales';
   title2 'of over';
   title3 'One Thousand Dollars';
run;

Program Description

Specify the report options and columns, define the group and analysis columns, and specify the titles. DATA= specifies the output data set from the first PROC REPORT step as the input data set for this report. The BOX option draws an outline around the output, separates the column headings from the body of the report, and separates rows and columns of data. The TITLE statements specify a title for the report.
proc report data=temp box nowd;
   column manager sales;
   define manager / group format=$mgrfmt.;
   define sales / analysis sum format=dollar11.2;
   title 'Managers with Daily Sales';
   title2 'of over';
   title3 'One Thousand Dollars';
run;

Report Based on the Output Data Set

Managers with Daily Sales of over One Thousand Dollars