Previous Page | Next Page

Creating Detail and Summary Reports with the REPORT Procedure

Creating Simple Reports


Displaying All the Variables

By default, PROC REPORT uses all of the variables in the data set. The layout of the report depends on the type of variables in the data set. If the data set contains any character variables, then PROC REPORT generates a simple detail report that lists the values of all the variables and the observations in the data set. If the data set contains only numeric variables, then PROC REPORT sums the value of each variable over all observations in the data set and produces a one-line summary of the sums. To produce a detail report for a data set with only numeric values, you have to define the columns in the report.

By default, PROC REPORT opens the REPORT window so that you can modify a report repeatedly and see the modifications immediately. To run PROC REPORT without the REPORT window and send your results to the SAS procedure output, you must use the NOWINDOWS option in the PROC REPORT statement.

The following PROC REPORT step creates the default detail report for the first quarter sales:

options linesize=80 pageno=1 nodate;

proc report data=year_sales nowindows;
   where quarter='1';
   title1 'TruBlend Coffee Makers, Inc.'; 
   title2 'First Quarter Sales Report';
run;

The WHERE statement specifies a condition that SAS uses to select observations from the YEAR_SALES data set. Before PROC REPORT builds the report, SAS selectively processes observations so that the report contains only data for the observations from the first quarter. For additional information about WHERE processing, see Selecting Observations.

The following detail report shows all the variable values for those observations in YEAR_SALES that contains first quarter sales data:

The Default Report When the Data Set Contains Character Values

                          TruBlend Coffee Makers, Inc.4                         1
                           First Quarter Sales Report

                                                                     AmountSol
 Month1    Quarter   SalesRep        Type          Units      Price          d2 
 01        1         Hollingsworth   Deluxe          260       49.5      128703 
 01        1         Garcia          Standard         41      30.97    1269.77
 01        1         Hollingsworth   Standard        330      30.97    10220.1
 01        1         Jensen          Standard        110      30.97     3406.7
 01        1         Garcia          Deluxe          715       49.5    35392.5
 01        1         Jensen          Standard        675      30.97   20904.75
 02        1         Garcia          Standard       2045      30.97   63333.65
 02        1         Garcia          Deluxe           10       49.5        495
 02        1         Garcia          Standard         40      30.97     1238.8
 02        1         Hollingsworth   Standard       1030      30.97    31899.1
 02        1         Jensen          Standard        153      30.97    4738.41
 02        1         Garcia          Standard         98      30.97    3035.06
 03        1         Hollingsworth   Standard        125      30.97    3871.25
 03        1         Jensen          Standard        154      30.97    4769.38
 03        1         Garcia          Standard        118      30.97    3654.46
 03        1         Hollingsworth   Standard         25      30.97     774.25
 03        1         Jensen          Standard        525      30.97   16259.25
 03        1         Garcia          Standard        310      30.97     9600.7
The following list corresponds to the numbered items in the preceding report:

[1] The order of the columns corresponds to the position of the variables in the data set.

[2] The default column width for numeric variables is nine. Therefore, the column label for AmountSold wraps across two lines.

[3] A blank line does not automatically appear between the column labels and the data values.

[4] The top of the report has a title, produced by the TITLE statement.

The following PROC REPORT step produces the default summary report when the YEAR_SALES data set contains only numeric values:

options linesize=80 pageno=1 nodate;
proc report data=year_sales (keep=Units AmountSold)
            colwidth=10 nowindows;
   title1 'TruBlend Coffee Makers, Inc.'; 
   title2 'Total Yearly Sales';
run;

The KEEP= data set option specifies to process only the numeric variables Units and Amountsold. PROC REPORT uses these variables to create the report. The COLWIDTH= option increases the column width so that the column label for AmountSold displays on a single line.

The following report displays a one-line summary for the two numeric variables:

The Default Report When the Data Set Contains Only Numeric Values

                          TruBlend Coffee Makers, Inc.                         1
                               Total Yearly Sales

                                  Units  AmountSold
                                  40989  1320479.48
PROC REPORT computed the one-line summary for Units and AmountSold by summing the value of each variable for all the observations in the data set.

Specifying and Ordering the Columns

The first step in constructing a report is to select the columns that you want to appear in the report. By default, the report contains a column for each variable and the order of the columns corresponds to the order of the variables in the data set.

You use the COLUMN statement to specify the variables to use in the report and the arrangement of the columns. In the COLUMN statement you can list data set variables, statistics that are calculated by PROC REPORT, or variables that are computed from other items in the report.

The following program creates a four column sales report for the first quarter:

options linesize=80 pageno=1 nodate;

proc report data=year_sales nowindows;
   where Quarter='1';
   column SalesRep Month Type Units;
   title1 'TruBlend Coffee Makers, Inc.'; 
   title2 'First Quarter Sales Report';
run;

The COLUMN statement specifies the order of the items in the report. The first column lists the values in SalesRep, the second column lists the values in Month, and so forth.

The following output shows the report:

Displaying Selected Columns

                          TruBlend Coffee Makers, Inc.                         1
                           First Quarter Sales Report

                 SalesRep        Month     Type          Units
                 Hollingsworth   01        Deluxe          260
                 Garcia          01        Standard         41
                 Hollingsworth   01        Standard        330
                 Jensen          01        Standard        110
                 Garcia          01        Deluxe          715
                 Jensen          01        Standard        675
                 Garcia          02        Standard       2045
                 Garcia          02        Deluxe           10
                 Garcia          02        Standard         40
                 Hollingsworth   02        Standard       1030
                 Jensen          02        Standard        153
                 Garcia          02        Standard         98
                 Hollingsworth   03        Standard        125
                 Jensen          03        Standard        154
                 Garcia          03        Standard        118
                 Hollingsworth   03        Standard         25
                 Jensen          03        Standard        525
                 Garcia          03        Standard        310

Ordering the Rows

You control much of the layout of a report by deciding how you use the variables. You tell PROC REPORT how to use a variable by specifying a usage option in the DEFINE statement for the variable.

To specify the order of the rows in the report, you can use the ORDER option in one or more DEFINE statements. PROC REPORT orders the rows of the report according to the values of the ORDER variables. If the report contains multiple ORDER variables, then PROC REPORT first orders rows according to the values of the first ORDER variable in the COLUMN statement.(footnote 1) Within each value of the first ORDER variable, the procedure orders rows according to the values of the second ORDER variable in the COLUMN statement, and so forth.

The following program creates a detail report of sales for the first quarter that is ordered by the sales representatives and month:

options linesize=80 pageno=1 nodate;

proc report data=year_sales nowindows;
   where Quarter='1';
   column SalesRep Month Type Units;
   define SalesRep / order;
   define Month / order;
   title1 'TruBlend Coffee Makers, Inc.'; 
   title2 'First Quarter Sales Report';
run;

The DEFINE statements specify that SalesRep and Month are the ORDER variables. The COLUMN statement specifies the order of the columns. By default, the rows are ordered by the ascending formatted values of SalesRep. The rows for each sales representative are ordered by the values of Month.

The following output shows the report:

Ordering the Rows

                          TruBlend Coffee Makers, Inc.                         1
                           First Quarter Sales Report

                 SalesRep        Month     Type          Units
                 Garcia          01        Standard         41
                                           Deluxe          715
                                 02        Standard       2045
                                           Deluxe           10
                                           Standard         40
                                           Standard         98
                                 03        Standard        118
                                           Standard        310
                 Hollingsworth   01        Deluxe          260
                                           Standard        330
                                 02        Standard       1030
                                 03        Standard        125
                                           Standard         25
                 Jensen          01        Standard        110
                                           Standard        675
                                 02        Standard        153
                                 03        Standard        154
                                           Standard        525
PROC REPORT does not repeat the values of the ORDER variables from one row to the next when the values are the same.

Consolidating Several Observations into a Single Row

You can create summary reports with PROC REPORT by defining one or more GROUP variables. A group is a set of observations that has a unique combination of values for all GROUP variables. PROC REPORT tries to consolidate, or summarize, each group into one row of the report.

To consolidate all columns across a row, you must define all variables in the report as either GROUP, ANALYSIS, COMPUTED, or ACROSS. The GROUP option in one or more DEFINE statements identifies the variables that PROC REPORT uses to form groups. You can define more than one variable as a GROUP variable, but GROUP variables must precede variables of the other types of usage. PROC REPORT determines the nesting by the order of the variables in the COLUMN statement. For more information about defining the usage of a variable, see Constructing the Layout.

The value of an ANALYSIS variable for a group is the value of the statistic that PROC REPORT computes for all observations in a group. For each ANALYSIS variable, you can specify the statistic in the DEFINE statement. By default, PROC REPORT uses all numeric variables as the ANALYSIS variables and computes the SUM statistic. The statistics that you can request in the DEFINE statement are as follows:

Descriptive Statistics
Descriptive statistic keywords
CSS PCTSUM
CV RANGE
MAX STD
MEAN STDERR
MIN SUM
N SUMWGT
NMISS USS
PCTN VAR
Quantile statistic keywords
MEDIAN|P50 Q3|P75
P1 P90
P5 P95
P10 P99
Q1|P25 QRANGE
Hypothesis testing keyword
PRT T

For definitions and discussion of these elementary statistics, see the Appendix in the Base SAS Procedures Guide.

The following program creates a summary report that shows the total yearly sales for each sales representative:

options linesize=80 pageno=1 nodate;

proc report data=year_sales nowindows colwidth=10;
   column SalesRep Units AmountSold;
   define SalesRep /group;1 
   define Units / analysis sum;2 
   define AmountSold/ analysis sum;3 
   title1 'TruBlend Coffee Makers Sales Report';
   title2 'Total Yearly Sales';
run;

The following list corresponds to the numbered items in the preceding program:

[1] The DEFINE statement specifies that SalesRep is the GROUP variable.

[2] The DEFINE statement specifies that Units is an ANALYSIS variable and specifies that PROC REPORT computes the SUM statistic.

[3] The DEFINE statement specifies that AmountSold is an ANALYSIS variable and specifies that PROC REPORT computes the SUM statistic.

The following output shows the report:

Grouping Multiple Observations in a Summary Report

                      TruBlend Coffee Makers Sales Report                      1
                               Total Yearly Sales

                     SalesRep             Units  AmountSold
                     Garcia               15969   512070.78
                     Hollingsworth        10620    347246.1
                     Jensen               14400    461162.6
Each row of the report represents one group and summarizes all observations that have a unique value for SalesRep. PROC REPORT orders these rows in ascending order of the GROUP variable, which in this example is the sales representative ordered alphabetically. The values of the ANALYSIS variables are the sum of Units and AmountSold for all observations in a group, which in this case is the total units and amount sold by each sales representative.

Changing the Default Order of the Rows

You can modify the default ordering sequence for the rows of a report by using the ORDER= or DESCENDING option in the DEFINE statement. The ORDER= option specifies the sort order for a variable. You can order the rows by:

DATA

the order of the data in the input data set.

FORMATTED

ascending formatted values.

FREQ

ascending frequency count.

INTERNAL

ascending unformatted or internally stored values.

By default, PROC REPORT uses the formatted values of a variable to order the rows. The DESCENDING option reverses the sort sequence so that PROC REPORT uses descending values to order the rows.

The following program creates a detail report of the first quarter sales that is ordered by number of sales:

options linesize=80 pageno=1 nodate;

proc report data=year_sales nowindows;
   where Quarter='1';
   column SalesRep Type Units Month;
   define SalesRep / order1  order=freq;2 
   define Units / order1  descending;3 
   define Type / order1 ;
   title1 'TruBlend Coffee Makers, Inc.'; 
   title2 'First Quarter Sales Report';
run;

The following list corresponds to the numbered items in the preceding program:

[1] The DEFINE statements specify that SalesRep, Units, and Type are ORDER variables that correspond to the number of sales each sales representative made.

[2] The ORDER=FREQ option orders the rows of the report by the frequency of SalesRep.

[3] The DESCENDING option orders the rows for UNITS from the largest to the smallest value.

.

The following output shows the report:

Changing the Order Sequence of the Rows

                          TruBlend Coffee Makers, Inc.                         1
                           First Quarter Sales Report
                 
                 SalesRep        Type          Units  Month1    
                 Hollingsworth2  Deluxe          260  01      
                                 Standard3      1030  02      
                                               4 330  01      
                                                 125  03      
                                                  25  03      
                 Jensen          Standard        675  01      
                                                 525  03      
                                                 154  03      
                                                 153  02      
                                                 110  01      
                 Garcia          Deluxe          715  01      
                                                  10  02      
                                 Standard       2045  02      
                                                 310  03      
                                                 118  03      
                                                  98  02      
                                                  41  01      
                                                  40  02      
The following list corresponds to the numbered items in the preceding report:

[1] The order of the columns corresponds to the order in which the variables are specified in the COLUMN statement. The order of the DEFINE statements does not affect the order of the columns.

[2] The order of the rows is by ascending frequency of SalesRep so that the sales representative with the least number of sales (observations) appears first while the sales representative with the greatest number of sales appears last.

[3] The order of the rows within SalesRep is by ascending formatted values of Type so that sales information about the deluxe coffee maker occurs before the standard coffee maker.

[4] The order of the rows within Type is by descending formatted values of Units so that the observation with the highest number of units sold appears first.


FOOTNOTE 1:   If you omit the COLUMN statement, then PROC REPORT processes the ORDER variables according to their position in the input data set. [arrow]

Previous Page | Next Page | Top of Page