Example 4.1. Customizing a Detail Report with Individualized Page Headers

Goal

Create a detail report that has a customized layout. Select specific information to list on each page. Customize the page and column headers by suppressing the default headings and replacing them with customized features.

Report

                                    Supreme Tire
 and Auto Repair
                                           Service
 Record

           Bert Allen
           1803 Knollton Ct.
           Bristol, NC  29345
           Ford F-150 1998

                                            Hours 
       Labor        Parts        Total
              Date         Description     Worked 
        Cost         Cost         Cost
          ----------     ---------------   ------ 
    --------     --------    ---------
          01/10/2006     replace belts        1.5 
      $97.50       $0.00        $97.50
          10/19/2005     oil change           0.5 
      $32.50      $18.00        $50.50
                                             ---- 
    --------     -------     ---------
                                              2.0 
     $130.00      $18.00       $148.00
                                             ---- 
    --------     -------     ---------





                            Labor cost is
 calculated at $65.00 per hour
                                Total cost = Labor
 cost + Parts cost

---------------------------------------------page 
break-----------------------------------------------

                                    Supreme Tire
 and Auto Repair
                                           Service
 Record

           Bert Allen
           1803 Knollton Ct.
           Bristol, NC  29345
           Jeep Cherokee 2000

                                            Hours 
       Labor        Parts        Total
              Date         Description     Worked 
        Cost         Cost         Cost
          ----------     ---------------   ------ 
    --------     --------    ---------
          01/10/2006     replace brakes       2.0 
     $130.00      $45.00       $175.00
          02/20/2006     rotate tires         1.0 
      $65.00      $20.00        $85.00
                         transmission         5.5 
     $357.50      $50.00       $407.50
          07/01/2005     oil change           0.5 
      $32.50      $18.00        $50.50
                                             ---- 
    --------     -------     ---------
                                              9.0 
     $585.00     $133.00       $718.00
                                             ---- 
    --------     -------     ---------





                            Labor cost is
 calculated at $65.00 per hour
                                Total cost = Labor
 cost + Parts cost


---------------------------------------------page 
break-----------------------------------------------

                                  Supreme Tire and
 Auto Repair
                                           Service
 Record

           Joe Smith
           1991 Cohansey St.
           New Ulm, NC  29545
           Ford F-150 1998

                                            Hours 
       Labor        Parts        Total
              Date         Description     Worked 
        Cost         Cost         Cost
          ----------     ---------------   ------ 
    --------     --------    ---------
          01/19/2006     oil change           0.5 
      $32.50      $18.00        $50.50
          02/25/2006     rotate tires         1.0 
      $65.00       $0.00        $65.00
                                             ---- 
    --------     -------     ---------
                                              1.5 
      $97.50      $18.00       $115.50
                                             ---- 
    --------     -------     ---------





                            Labor cost is
 calculated at $65.00 per hour
                                Total cost = Labor
 cost + Parts cost

---------------------------------------------page
 break-----------------------------------------------

                                   Supreme Tire
 and Auto Repair
                                          Service
 Record

          Sara Jones
          202 Stargate Dr.
          Dart, NC  29445
          Chrysler Voyager 2003

                                            Hours 
       Labor        Parts        Total
              Date         Description     Worked 
        Cost         Cost         Cost
          ----------     ---------------   ------ 
    --------     --------    ---------
          12/07/2005     align frontend       1.5 
      $97.50      $20.00       $117.50
                         rotate tires         1.0 
      $65.00      $20.00        $85.00
                                             ---- 
    --------     -------     ---------
                                              2.5 
     $162.50      $40.00       $202.50
                                             ---- 
    --------     -------     ---------





                            Labor cost is
 calculated at $65.00 per hour
                                Total cost = Labor
 cost + Parts cost


Example Features

Data SetSERVICE
Featured StepPROC REPORT
Featured Step Statements and OptionsDEFINE statement: ANALYSIS, COMPUTED, NOPRINT, ORDER, and SUM options

COMPUTE blocks

BREAK AFTER statement

LINE statement
Formatting FeaturesPROC REPORT statement: NOHEADER option

PROC REPORT statement: SPACING= and WIDTH= options when sending output to the LISTING destination

LINE statement: column positioning when sending output to the LISTING destination
Related TechniqueOPTIONS NOBYLINE, PROC REPORT with a BY statement, and TITLE statements with #BYVAL
A Closer LookUnderstanding the Use of ORDER and NOPRINT in PROC REPORT

Example Overview

This report shows the service records for cars brought to a car repair shop. A car can have multiple service records, and all the service records for one car are printed on one page. A heading on each page identifies the car and its owner.

Each observation in the SERVICE data set corresponds to one service record on one date for one car. A row in the body of each page of the report corresponds to one observation in SERVICE.

Some variables in the report appear in columns. Others appear only in the page heading. The columns include data set variables and computed variables.

Note that one customer has two cars and that two customers have the same car model.

Many of the features of the main example require that you send the report to a LISTING destination. Modifications to the program that would produce a similar report for a nonlisting destination are described in the Related Technique section.

This report suppresses the default placement of column headings and instead writes column headings with programming statements that are placed in a COMPUTE BEFORE block. The programming statements place the customer information in the upper left corner of the report and write the column headings in specific column positions of the report. The explicit column positioning of the column headings would not work if the report were sent to a nonlisting destination.

Program

 
proc report data=service nowindows

Suppress all default column headers.
     noheader

When sending the report to a LISTING destination, separate the columns with five spaces.
     spacing=5;
  title 'Supreme Tire and Auto Repair';
  title2 'Service Record';

  footnote1 'Labor cost is calculated at $65.00
             per hour';
  footnote2 'Total cost = Labor cost + Parts cost';

List the columns in the order in which they should appear in the report. Include those that appear in the report columns as well as those that appear in the customized page headers.
  column name address city state zipcode cartype
       date workdone hours labor parts total;

Apply the same attributes to all variables in the COLUMN statement between the first in the list and the last in the list. Order the data based on the values of these variables, but do not print them.
  define name--zipcode / order noprint;

 
  define cartype       / order noprint;
  define date          / order format=mmddyy10.;
  define workdone      / order;

Calculate the sum statistics on these two data set variables. Specify the column width when sending output to the LISTING destination.
  define hours / analysis sum format=4.1
                 width=4;
  define parts / analysis sum format=dollar8.2
                 width=7;

Define two computed variables.
  define labor / computed format=dollar8.2;
  define total / computed format=dollar8.2;

Compute values for LABOR and TOTAL in separate COMPUTE blocks. Refer to the analysis variables HOURS and PARTS by their compound names. The compound name identifies the variable and the statistic associated with it.
  compute labor;
    labor=hours.sum*65.00;
  endcomp;

  compute total;
    total=labor+parts.sum;
  endcomp;

Customize the page heading and the column headings. Execute this block every time the value of CARTYPE changes, which is before PROC REPORT writes the first row for that car.
  compute before cartype;
    length fulladdress $ 55;
    fulladdress=catx(' ',cats(city,','),state,
                     zipcode);

Write the page heading lines with column and formatted output.
    line @2 name $20.;
    line @2 address $20.;
    line @2 line @2 fulladdress $55.;
    line @2 cartype $21.;
    line ' ';

Write the column headings in specific locations.
    line @36 'Hours' @49 'Labor' @62 'Parts'
         @74 'Total';
    line @6 'Date'  @19 'Description' @35 'Worked'
         @50 'Cost' @63 'Cost' @75 'Cost';
    line @2 10*'-'   @17 15*'-' @35 6*'-'
         @46 8*'-' @59 8*'-' @71 8*'-';
  endcomp;

Create a summary line after the last row for each car. Start a new page after the summary line.
    break after cartype / summarize ol ul page;

  run;


Related Technique

The main program for this example writes page and column headings to explicit locations on a page. When you send this report to a nonlisting destination, these instructions are ignored and the formatting of the report is out of alignment.

The following program removes the explicit positioning of data in the headings of the report in the preceding example. It reinstates column headers by removing the NOHEADER option.

The TITLE statements create the page headings, and the BYVAL feature in the TITLE statements customizes these headings. If you tried to write the page headings with a COMPUTE BEFORE block and did not include the PROC REPORT NOHEADER option, PROC REPORT places the column headings before the page headings.

Figure 4.1 shows the first page of the report when sent to the RTF nonlisting destination.

Figure 4.1. First Page of Output from Related Technique Sent to the RTF Destination


The program that created the output in Figure 4.1 follows.

Sort the data set by the variables that will be included in the TITLE statements.
proc sort data=service;
  by name address city state zipcode cartype;
run;

Prevent BY lines from being printed above each BY group of the report.
options nobyline;


proc report data=service nowd;
  title 'Supreme Tire and Auto Repair';
  title2 'Service Record';

Specify the page headings in TITLE statements and include in the title text the current values of the BY variables. When sending to a nonlisting destination, left-justify the title text.
  title4 justify=left "#byval(name)";
  title5 justify=left "#byval(address)";
  title6 justify=left "#byval(city), "
         "#byval(state)   #byval(zipcode)";
  title7 justify=left "#byval(cartype)";

Include a BY statement so that the data set is processed in BY groups and the BY-group values are available to be inserted into the title text.
  by name address city state zipcode cartype;

Include one of the BY variables (CARTYPE) on the COLUMN statement because it’s necessary for PROC REPORT to use its values to determine when to start a new page and compute summaries.
  column cartype date workdone hours labor parts
 total;

Specify CARTYPE as an ORDER variable, even though this specification appears redundant because of the inclusion of CARTYPE on the BY statement. Do not display the values of CARTYPE, but use its values later to determine when to start a new page and compute summaries.
  define cartype / order noprint;

  define date / order format=mmddyy10. 'Date';
  define workdone / order 'Description';

  define hours / analysis sum format=4.1
                'Hours/Worked';
  define parts / analysis sum format=dollar8.2
                 'Parts/Cost';

  define labor / computed format=dollar8.2
                 'Labor/Cost';
  define total / computed format=dollar8.2
                 'Total/Cost';

  compute labor;
    labor=hours.sum*65.00;
  endcomp;

  compute total;
    total=labor+parts.sum;
  endcomp;

Summarize the information for each car and start the information for each car on a new page.
  break after cartype / summarize ol ul page;

Instead of putting the cost information in footnotes as was done in the main program for this example, place it at the end of the body of the report.
  compute after cartype;
    line 'Labor cost is calculated at $65.00 per
 hour';
    line 'Total cost = Labor cost + Parts cost';
  endcomp;
run;


A Closer Look

Understanding the Use of ORDER and NOPRINT in PROC REPORT

Combining the ORDER and NOPRINT options in the definition of a variable in PROC REPORT provides you with a lot of flexibility for customizing a report.

The ORDER option orders the rows of the report.
The ORDER option also lets you place customized text at points in the report where the value of that variable changes.
The NOPRINT option prevents a variable from appearing in a column. NOPRINT has no effect on the ORDER option. A variable defined with both options affects the order of the rows of the report, even though it does not appear in a column of the report.

The page heading in the main example identifies the car and its owner. This information appears before the first row of repair charges. Variables that do not appear in a column appear in the page heading.

The report is ordered by the car owner’s name and within that by car for customers with more than one car with repair records.

The ORDER option on the DEFINE statements arranges the observations, while the NOPRINT option suppresses their display as columns. The values of these items, however, are still available to the step. The COMPUTE BEFORE CARTYPE block references them and writes the page heading.

Where to Go from Here

The BYLINE/NOBYLINE SAS System Options. See “SAS System Options” in SAS 9.1 Language Reference: Dictionary.

Inserting BY-group information in titles. See “Creating Titles that Contain BY-Group Information” in the “Fundamental Concepts in Using Base SAS Procedures” section of Base SAS 9.1 Procedures Guide.

PROC REPORT reference, usage information, and additional examples. See “The REPORT Procedure” in the “Procedures” section of Base SAS 9.1 Procedures Guide.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.191.214