Chapter Contents

Previous

Next
The REPORT Procedure

Example 10: Calculating Percentages


Procedure features:
COLUMN statement arguments:
PCTSUM
SUM
spanning heads
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 header. A single header also spans all the columns. This header 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 header.

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

libname proclib 'SAS-data-library';
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
[HTML Output]  [Listing Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.