REPORT Procedure

Example 7: Storing and Reusing a Report Definition

Features:
PROC REPORT statement options:
NAMED
OUTREPT=
REPORT=
WRAP
Other features:

TITLE statement

WHERE statement

Data set: GROCERY
Formats: $MGRFMT

$DEPTFMT

$SCTRFMT

Details

The first PROC REPORT step in this example creates a report that displays one value from each column of the report, using two rows to do so, before displaying another value from the first column. (By default, PROC REPORT displays values for only as many columns as it can fit on one page. It fills a page with values for these columns before starting to display values for the remaining columns on the next page.)
Each item in the report is identified in the body of the report rather than in a column heading.
The report definition created by the first PROC REPORT step is stored in a catalog entry. The second PROC REPORT step uses it to create a similar report for a different sector of the city.

Program to Store a Report Definition

libname proclib
'SAS-library';
options fmtsearch=(proclib);
proc report data=grocery nowd
            named
            wrap
            ls=64 ps=36
            outrept=proclib.reports.namewrap;
   column sector manager department sales;
   define sector / format=$sctrfmt.;
   define manager / format=$mgrfmt.;
   define department / format=$deptfmt.;
   define sales / format=dollar11.2;
   where manager='1';
   title "Sales Figures for Smith on &sysdate";
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. The NOWD option runs PROC REPORT without the REPORT window and sends its output to the open output destinations. NAMED writes name= in front of each value in the report, where name= is the column heading for the value. When you use NAMED, PROC REPORT suppresses the display of column headings at the top of each page.
proc report data=grocery nowd
            named
            wrap
            ls=64 ps=36
            outrept=proclib.reports.namewrap;
Specify the report columns. The report contains a column for Sector, Manager, Department, and Sales.
   column sector manager department sales;
Define the display and analysis variables. Because no usage is specified in the DEFINE statements, PROC REPORT uses the defaults. The character variables (Sector, Manager, and Department) are display variables. Sales is an analysis variable that is used to calculate the sum statistic. FORMAT= specifies the formats to use in the report.
   define sector / format=$sctrfmt.;
   define manager / format=$mgrfmt.;
   define department / format=$deptfmt.;
   define sales / format=dollar11.2;
Select the observations to process. A report definition might differ from the SAS program that creates the report. In particular, PROC REPORT stores neither WHERE statements nor TITLE statements.
   where manager='1';
Specify the title. SYSDATE is an automatic macro variable that returns the date when the SAS job or SAS session began. The TITLE statement uses double rather than single quotation marks so that the macro variable resolves.
   title "Sales Figures for Smith on &sysdate";
run;

Output

The following output is the output from the first PROC REPORT step, which creates the report definition.
Sales Figures for Smith

Program to Use a Report Definition

options fmtsearch=(proclib);
 proc report data=grocery report=proclib.reports.namewrap
            nowd;
   where sector='sw';
   title "Sales Figures for the Southwest Sector on &sysdate";
run;

Program Description

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, load the report definition, and select the observations to process. REPORT= uses the report definition that is stored in PROCLIB.REPORTS.NAMEWRAP to produce the report. The second report differs from the first one because it uses different WHERE and TITLE statements.
 proc report data=grocery report=proclib.reports.namewrap
            nowd;
   where sector='sw';
   title "Sales Figures for the Southwest Sector on &sysdate";
run;

Output

Sales Figures for the Southwest Sector