REPORT Procedure

Example 16: Specifying Style Elements for ODS Output in Multiple Statements

Features:
STYLE= option in:
PROC REPORT statement
CALL DEFINE statement
COMPUTE statement
DEFINE statement
Other features:

ODS PDF statement

ODS RTF statement

Data set: GROCERY
Formats: $MGRFMT

$DEPTFMT

Details

This example creates HTML, PDF, and RTF files and sets the style elements for each location in the report in the PROC REPORT statement. It then overrides some of these settings by specifying style elements in other statements.

Program

libname proclib
'SAS-library';
options fmtsearch=(proclib);
ods pdf file='external-PDF-file';
ods rtf file='external-RTF-file';
proc report data=grocery nowd headline headskip
style(report)=[cellspacing=5 borderwidth=10 bordercolor=blue]
style(header)=[color=yellow
               fontstyle=italic fontsize=6]
style(column)=[color=moderate brown
               fontfamily=helvetica fontsize=4]
style(lines)=[color=white backgroundcolor=black
              fontstyle=italic fontweight=bold fontsize=5]
style(summary)=[color=cx3e3d73 backgroundcolor=cxaeadd9
                fontfamily=helvetica fontsize=3 textalign=r];
   column manager department sales;
   define manager / order
                    order=formatted
                    format=$mgrfmt.
                    'Manager'
                    style(header)=[color=white
                                   backgroundcolor=black];
   define department / order
                       order=internal
                       format=$deptfmt.
                       'Department'
                       style(column)=[fontstyle=italic];
   break after manager / summarize;
   compute after manager
           / style=[fontstyle=roman fontsize=3 fontweight=bold
             backgroundcolor=white color=black];
      line 'Subtotal for ' manager $mgrfmt. 'is '
            sales.sum dollar7.2 '.';
   endcomp;
   compute sales;
      if sales.sum>100 and _break_=' ' then
      call define(_col_, "style",
                  "style=[backgroundcolor=yellow
                          fontfamily=helvetica
                          fontweight=bold]");
   endcomp;
   compute after;
       line 'Total for all departments is: '
            sales.sum dollar7.2 '.';
   endcomp;
   where sector='se';
   title 'Sales for the Southeast Sector';
run;
ods pdf close;
ods rtf close;

Program Description

Declare the PROCLIB library. The PROCLIB library is used to store user-created formats.
libname proclib
'SAS-library';
Specify the format search library.The SAS system option FMTSEARCH= adds the SAS library PROCLIB to the search path that is used to locate formats.
options fmtsearch=(proclib);
Specify the ODS output filenames. By opening multiple ODS destinations, you can produce multiple output files in a single execution. HTML output is produced by default. The ODS PDF statement produces output in Portable Document Format (PDF). The ODS RTF statement produces output in Rich Text Format (RTF). The output from PROC REPORT goes to each of these files.
ods pdf file='external-PDF-file';
ods rtf file='external-RTF-file';
Specify the report options. The NOWD option runs PROC REPORT without the REPORT window. In this case, SAS writes the output to the traditional procedure output, the HTML body file, and the RTF and PDF files.
proc report data=grocery nowd headline headskip
Specify the style attributes for the report. This STYLE= option sets the style element for the structural part of the report. Because no style element is specified, PROC REPORT uses all the style attributes of the default style element for this location except for the ones that are specified here.
style(report)=[cellspacing=5 borderwidth=10 bordercolor=blue]
Specify the style attributes for the column headings. This STYLE= option sets the style element for all column headings. Because no style element is specified, PROC REPORT uses all the style attributes of the default style element for this location except for the ones that are specified here.
style(header)=[color=yellow
               fontstyle=italic fontsize=6]
Specify the style attributes for the report columns. This STYLE= option sets the style element for all the cells in all the columns. Because no style element is specified, PROC REPORT uses all the style attributes of the default style element for this location except for the ones that are specified here.
style(column)=[color=moderate brown
               fontfamily=helvetica fontsize=4]
Specify the style attributes for the compute block lines. This STYLE= option sets the style element for all the LINE statements in all compute blocks. Because no style element is specified, PROC REPORT uses all the style attributes of the default style element for this location except for the ones that are specified here.
style(lines)=[color=white backgroundcolor=black
              fontstyle=italic fontweight=bold fontsize=5]
Specify the style attributes for the report summaries. This STYLE= option sets the style element for all the default summary lines. Because no style element is specified, PROC REPORT uses all the style attributes of the default style element for this location except for the ones that are specified here.
style(summary)=[color=cx3e3d73 backgroundcolor=cxaeadd9
                fontfamily=helvetica fontsize=3 textalign=r];
Specify the report columns. The report contains columns for Manager, Department, and Sales.
   column manager department sales;
Define the first sort order variable. In this report Manager is an order variable. PROC REPORT arranges the rows first by the value of Manager (because it is the first variable in the COLUMN statement). ORDER= specifies that values of Manager are arranged according to their formatted values. FORMAT= specifies the format to use for this variable. Text in quotation marks specifies the column headings.
   define manager / order
                    order=formatted
                    format=$mgrfmt.
                    'Manager'
Specify the style attributes for the first sort order variable column heading. The STYLE= option sets the foreground and background colors of the column heading for Manager. The other style attributes for the column heading will match the ones that were established for the HEADER location in the PROC REPORT statement.
                    style(header)=[color=white
                                   backgroundcolor=black];
Define the second sort order variable. In this report Department is an order variable. PROC REPORT arranges the rows first by the value of Manager (because it is the first variable in the COLUMN statement), then by the value of Department. ORDER= specifies that values of Department are arranged according to their internal values. FORMAT= specifies the format to use for this variable. Text in quotation marks specifies the column heading.
   define department / order
                       order=internal
                       format=$deptfmt.
                       'Department'
Specify the style attributes for the second sort order variable column.The STYLE= option sets the font of the cells in the column Department to italic. The other style attributes for the cells will match the ones that were established for the COLUMN location in the PROC REPORT statement.
                       style(column)=[fontstyle=italic];
Produce a report summary. The BREAK statement produces a default summary after the last row for each manager. SUMMARIZE writes the values of Sales (the only analysis or computed variable in the report) in the summary line. PROC REPORT sums the values of Sales for each manager because Sales is an analysis variable that is used to calculate the Sum statistic.
   break after manager / summarize;
Produce a customized summary. The COMPUTE statement begins a compute block that produces a customized summary at the end of the report. This STYLE= option specifies the style element to use for the text that is created by the LINE statement in this compute block. This style element switches the foreground and background colors that were specified for the LINES location in the PROC REPORT statement. It also changes the font style, the font weight, and the font size.
   compute after manager
           / style=[fontstyle=roman fontsize=3 fontweight=bold
             backgroundcolor=white color=black];
Specify the text for the customized summary. The LINE statement places the quoted text and the values of Manager and Sales.sum (with the formats $MGRFMT. and DOLLAR7.2) in the summary. An ENDCOMP statement must end the compute block.
      line 'Subtotal for ' manager $mgrfmt. 'is '
            sales.sum dollar7.2 '.';
   endcomp;
Produce a customized background for the analysis column. This compute block specifies a background color and a bold font for all cells in the Sales column that contain values of 100 or greater and that are not summary lines.
   compute sales;
      if sales.sum>100 and _break_=' ' then
      call define(_col_, "style",
                  "style=[backgroundcolor=yellow
                          fontfamily=helvetica
                          fontweight=bold]");
   endcomp;
Produce a customized end-of-report summary. This COMPUTE statement begins a compute block that executes at the end of the report. The LINE statement writes the quoted text and the value of Sales.sum (with the DOLLAR7.2 format). An ENDCOMP statement must end the compute block.
   compute after;
       line 'Total for all departments is: '
            sales.sum dollar7.2 '.';
   endcomp;
Select the observations to process. The WHERE statement selects for the report only the observations for stores in the southeast sector.
   where sector='se';
Specify the title.
   title 'Sales for the Southeast Sector';
run;
Close the ODS destinations.
ods pdf close;
ods rtf close;

HTML Output

Sales for the Southeast Sector

PDF Output

Sales for the Southeast Sector

RTF Output

Sales for the Southeast Sector