Previous Page | Next Page

The REPORT Procedure

Example 9: Writing a Customized Summary on Each Page


Procedure features:

BREAK statement options:

OL

PAGE

SUMMARIZE

COMPUTE statement arguments:

with a computed variable as report-item

BEFORE break-variable

AFTER break-variable with conditional logic

BEFORE _PAGE_

DEFINE statement options:

NOPRINT

LINE statement:

pointer controls

quoted text

repeating a character string

variable values and formats

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

The report in this example displays a record of one day's sales for each store. The rows are arranged so that all the information about one store is together, and the information for each store begins on a new page. Some variables appear in columns. Others appear only in the page heading that identifies the sector and the store's manager.

The heading that appears at the top of each page is created with the _PAGE_ argument in the COMPUTE statement.

Profit is a computed variable based on the value of Sales and Department.

The text that appears at the bottom of the page depends on the total of Sales for the store. Only the first two pages of the report appear here.


Program

 Note about code
libname proclib 'SAS-library';
 Note about code
options nodate pageno=1 linesize=64 pagesize=30
        fmtsearch=(proclib);
 Note about code
proc report data=grocery nowd
            headline headskip;
 Note about code
   title 'Sales for Individual Stores';
 Note about code
   column sector manager department sales Profit;
 Note about code
   define sector / group noprint;
   define manager / group noprint;
   define profit / computed format=dollar11.2;
   define sales / analysis sum format=dollar11.2;
   define department / group format=$deptfmt.;
 Note about code
   compute profit;
      if department='np1' or department='np2' 
         then profit=0.4*sales.sum;
      else profit=0.25*sales.sum;
   endcomp;
 Note about code
    compute before _page_ / left;
      line sector $sctrfmt. ' Sector';
      line 'Store managed by ' manager $mgrfmt.;
      line ' ';
      line ' ';
      line ' ';
   endcomp;
 Note about code
   break after manager / ol summarize page;
 Note about code
   compute after manager;
 Note about code
      length text $ 35;
 Note about code
      if sales.sum lt 500 then
         text='Sales are below the target region.';
      else if sales.sum ge 500 and sales.sum lt 1000 then
         text='Sales are in the target region.';
      else if sales.sum ge 1000 then
         text='Sales exceeded goal!';
      line ' ';
      line text $35.;
   endcomp;
   run;

Output

                  Sales for Individual Stores                  1

Northeast Sector                                                
Store managed by Alomar                                         
                                                                
                                                                
                                                                
              Department        Sales       Profit
              ------------------------------------
                                                  
              Canned          $420.00      $168.00
              Meat/Dairy      $190.00       $47.50
              Paper            $90.00       $36.00
              Produce          $86.00       $21.50
                          -----------  -----------
                              $786.00      $196.50
                                                                
                Sales are in the target region.                 
                  Sales for Individual Stores                  2

Northeast Sector                                                
Store managed by Andrews                                        
                                                                
                                                                
                                                                
              Department        Sales       Profit
              ------------------------------------
                                                  
              Canned          $420.00      $168.00
              Meat/Dairy      $300.00       $75.00
              Paper           $200.00       $80.00
              Produce         $125.00       $31.25
                          -----------  -----------
                            $1,045.00      $261.25
                                                                
                      Sales exceeded goal!                      

Previous Page | Next Page | Top of Page