Previous Page | Next Page

The REPORT Procedure

Example 10: Calculating Percentages


Procedure features:

COLUMN statement arguments:

PCTSUM

SUM

spanning headings

COMPUTE statement options:

CHAR

LENGTH=

DEFINE statement options:

COMPUTED

FLOW

WIDTH=

RBREAK statement options:

OL

SUMMARIZE

Other features:

TITLE statement

Data set: GROCERY
Formats: $MGRFMT. and $DEPTFMT.

The summary report in this example shows the total sales for each store and the percentage that these sales represent of sales for all stores. Each of these columns has its own heading. A single heading also spans all the columns. This heading looks like a title, but it differs from a title because it would be stored in a report definition. You must submit a null TITLE statement whenever you use the report definition, or the report will contain both a title and the spanning heading.

The report includes a computed character variable, COMMENT, that flags stores with an unusually high percentage of sales. The text of COMMENT wraps across multiple rows. It makes sense to compute COMMENT only for individual stores. Therefore, the compute block that does the calculation includes conditional code that prevents PROC REPORT from calculating COMMENT on the summary line.


Program

 Note about code
libname proclib 'SAS-library';
 Note about code
options nodate pageno=1 linesize=64 pagesize=60
        fmtsearch=(proclib);
 Note about code
proc report data=grocery nowd headline;
   title;
 Note about code
   column ('Individual Store Sales as a Percent of All Sales'
            sector manager sales,(sum pctsum) comment);
 Note about code
   define manager / group
                    format=$mgrfmt.;
   define sector / group
                   format=$sctrfmt.;
   define sales / format=dollar11.2
                  '';
   define sum / format=dollar9.2
                'Total Sales';
 Note about code
   define pctsum / 'Percent of Sales' format=percent6. width=8;
   define comment / computed width=20 '' flow;
 Note about code
   compute comment / char length=40;
 Note about code
      if sales.pctsum gt .15 and _break_ = ' '
      then comment='Sales substantially above expectations.';
      else comment=' ';
   endcomp;
 Note about code
   rbreak after / ol summarize;
run;

Output

                                                               1

       Individual Store Sales as a Percent of All Sales       
                                                              
                         Total   Percent                      
 Sector     Manager      Sales  of Sales                      
 -------------------------------------------------------------
 Northeast  Alomar     $786.00      12%                       
            Andrews  $1,045.00      17%   Sales substantially 
                                          above expectations. 
 Northwest  Brown      $598.00       9%                       
            Pelfrey    $746.00      12%                       
            Reveiz   $1,110.00      18%   Sales substantially 
                                          above expectations. 
 Southeast  Jones      $630.00      10%                       
            Smith      $350.00       6%                       
 Southwest  Adams      $695.00      11%                       
            Taylor     $353.00       6%                       
                     ---------  --------                      
                     $6,313.00     100%                       

Previous Page | Next Page | Top of Page