Example 6.2. Customizing a PROC REPORT Summary Report

Goal

Customize the appearance of the report produced in Example 3.8 by modifying style attributes with ODS. Replace features specific to the LISTING destination with those compatible with ODS nonlisting destinations. Send the output to a nonlisting destination.

Report

Example Features

Data SetCARSALES
Report ExampleExample 3.8
Featured StepPROC REPORT
Featured Step Statements and OptionsPROC REPORT statement ODS options: STYLE(LINES)= and STYLE(SUMMARY)= DEFINE statement ODS option: STYLE(COLUMN)=
Output Destination of ExampleRTF
A Closer LookComparing Example 3.8 and Example 6.2
Other Examples That Use This Data SetExamples 3.8 and 6.6

Example Overview

When you write a report program, you might need to consider the destination of the output. Some statements and options apply only to specific destinations. This example illustrates how you can change Example 3.8 to send it to a nonlisting destination instead of the LISTING destination.

The report in Example 3.8 summarized sales information by quarter for two car sales representatives and identified each sales representative’s best quarter. It also presented an annual sales summary for each sales representative and for both sales representatives combined.

Program

 
proc format;
   value mnthfmt 1-3 = '1st'
                 4-6 = '2nd'
                 7-9 = '3rd'
               10-12 = '4th';
run;

Do not send results to the LISTING destination.
ods listing close;

Send subsequent results to the RTF destination and save the results in a file.
ods rtf file='c:
eportsexample38.rtf';



proc report data=carsales nowindows

Override current style element attributes in specific locations of the report. Write the summary lines in bold.
            style(summary)={font_weight=bold}

Italicize the output produced by LINE statements and write them in bold. Center the output.
            style(lines)={font_weight=bold
                          font_style=italic
                          just=center};

   title 'Quality Motor Company';

   column name month numsold amtsold avgsales
          maxsales;

   define name     / group width=25
                     'Sales/Representative'

Write all values in the NAME column in bold.
                     style(column)={font_weight=bold};

   define month    / group width=8 'Quarter' center
                     format=mnthfmt. width=8;

   define numsold  / analysis sum
                     'Cars Sold/by/Quarter'
                     format=2. width=9;
   define amtsold  / analysis sum
                     'Total Sales/by/Quarter'
                     format=dollar13.2;

   define avgsales / computed 'Average/Sale'
                     format=dollar13.2;

   define maxsales / computed noprint;
   compute before name;
     bigsales=0;
     bigqtr=50;
   endcomp;

   compute avgsales;
      avgsales = amtsold.sum / numsold.sum;
   endcomp;

   compute maxsales;
     if _break_=' ' and bigsales lt amtsold.sum then
        do;
          bigsales=amtsold.sum;
          bigqtr=month;
     end;
   endcomp;

Summarize each sales representative’s information and write the sales representative’s totals at the end of the person’s quarterly sales results.
   break after name / summarize;

Replace the default summary line value for NAME and write a customized line after the sales representative’s totals.
   compute after name;

Define a character variable that will contain the contents of the customized summary line.
     length fullline $ 50;

Concatenate the elements of the customized line and assign the results to a character variable.
     fullline=catx(' ','Best Quarter for',
                cats(name,':'),
                put(bigqtr,mnthfmt.));

Assign a value to NAME for display in the NAME cell associated with the summary lines produced by the BREAK AFTER NAME statement.
     name=catx(' ','Sales Totals for ',name);

Write the customized summary line. Be sure to specify a format for FULLLINE, because the LINE statement requires a format for items such as data set variables, computed variables, and statistics.
     line fullline $50.;
   endcomp;

Summarize both sales representatives’ information and write the totals at the end of the report.
   rbreak after / summarize;

Assign a value to NAME for display in the NAME cell associated with the report summary line produced by the RBREAK AFTER statement.
   compute after;
     name='Annual Totals';
   endcomp;

run;

Terminate sending output to the RTF destination.
ods rtf close;

Send subsequent output to the LISTING destination.
ods listing;


A Closer Look

Comparing Example 3.8 and Example 6.2

The differences in the COMPUTE blocks, BREAK statement, and RBREAK statement between Example 3.8 and Example 6.2 result from the requirements of the output destinations of the two reports. The report in Example 3.8 was sent to the LISTING destination, whereas the report in Example 6.2 was sent to a nonlisting destination.

With no other programming changes, Example 3.8 sent to the RTF destination appears as shown in Figure 6.2.

Figure 6.2. Example 3.8 Output Sent to the RTF Destination


The results of the LINE statements that write the separator lines do not look appropriate in this example. The COMPUTE AFTER NAME block in Example 3.8 writes values starting in specific columns. The report sent to the RTF destination was written with a style that used a proportional font, so attempts to position the values in specific columns do not work.

Table 6.2 compares the COMPUTE blocks between the two examples.

Table 6.2. Comparing the COMPUTE Blocks between Examples 3.8 and 6.2
Example 3.8Example 6.2
  compute before name;
    bigsales=0;
    bigqtr=50;
    line @6 70*'=';
  endcomp;

  compute avgsales;
     avgsales = amtsold.sum / numsold.sum;
  endcomp;

  compute maxsales;
    if _break_=' ' and bigsales lt
       amtsold.sum then do;
        bigsales=amtsold.sum;
        bigqtr=month;
    end;
  endcomp;



  compute after name;
    length fullline $ 50;
    fullline=catx(' ','Best Quarter for',
                  cats(name,':'),
                  put(bigqtr,mnthfmt.));

    line @6 70*'=';
    line @6 'Sales Totals for ' name  $14.
         @42 numsold.sum 3.
         @45 amtsold.sum dollar15.2
         @60 avgsales dollar15.2;

    line @6 fullline $50.;

    line @6 70*'=';
    line ' ';
  endcomp;



  compute after;
    line @6 70*'=';
    line @6 'Annual Totals '
         @41 numsold.sum 4.
         @45 amtsold.sum dollar15.2
         @60 avgsales dollar15.2;
    line @6 70*'=';
    line ' ';
  endcomp;

  compute before name;
    bigsales=0;
    bigqtr=50;         1
  endcomp;


  compute avgsales;
     avgsales = amtsold.sum / numsold.sum;
  endcomp;

  compute maxsales;
    if _break_=' ' and bigsales lt
       amtsold.sum then do;
        bigsales=amtsold.sum;
        bigqtr=month;
    end;
  endcomp;

  break after name / summarize;      2

  compute after name;
    length fullline $ 50;
    fullline=catx(' ','Best Quarter for',
                  cats(name,':'),
                  put(bigqtr,mnthfmt.));


    name=catx(' ',                   3
              'Sales Totals for ',name);

                                     4

    line fullline $50.;



  endcomp;

  rbreak after / summarize;          5

  compute after;                     6
     name='Annual Totals';
  endcomp;


Remove the LINE statement from the COMPUTE BEFORE NAME block.

Replace the first two LINE statements in the COMPUTE AFTER NAME block with the BREAK AFTER NAME statement.

Assign a value to NAME for display in the NAME cell associated with the summary lines produced by the BREAK AFTER NAME statement.

Remove the explicit column specifications on the LINE statements. Keep only the LINE statement that writes out the “Best Quarter for....” Remove the LINE statements that write the separator lines and the blank line.

Remove all LINE statements from the COMPUTE AFTER block. Replace the LINE statements with the RBREAK AFTER statement.

Assign a value to NAME for display in the NAME cell associated with the report summary line produced by the RBREAK AFTER statement.

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

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