Example 6.14. Defining a Reusable Generic Style

Goal

Define a style that will be used repeatedly. Apply this style to a report. Add additional style attributes specific to this report. Send the report to a nonlisting destination.

Report

Example Features

Data SetCUSTRESP
Report ExampleExamples 3.10 and 6.13
Featured Steps and StatementPROC TEMPLATE

PROC TABULATE

ODS statement
Featured Step Statements and OptionsPROC TEMPLATE

DEFINE STYLE, PARENT=, REPLACE, and STYLE statements

Inline formatting

ODS statement: ESCAPECHAR=, STARTPAGE=, and STYLE= options

ODS STYLE= options placed on the PROC TABULATE TABLE statement, including the BOX= option
Additional FeaturesMacro programming SAS file input/output functions
Output Destination of ExampleRTF
A Closer LookLearning More about ODS Styles
Other Examples That Use This Data SetExamples 3.10 and 6.13

Example Overview

The three tables in this report present a survey of the customers of a business where products can be purchased either in a store or online. The report presents the three tables on one page, and a separate PROC TABULATE step produces each of the tables. This report is similar to those in Examples 3.10 and 6.13.

As in Example 6.13, this report is also sent to a nonlisting destination. It sets the ODS statement option STARTPAGE=NO to keep all the tables on one page.

This example modifies the report presented in Example 6.13 by applying a style defined by PROC TEMPLATE, by applying inline formatting with ODS ESCAPECHAR=, and by setting specific style attributes on the TABLE statement in each of the PROC TABULATE steps.

One of the goals of this example is to define a style that can be reused by other programs when you want to render the output from those programs the same way. This program starts by defining a style with PROC TEMPLATE that controls the major aspects of a report. It includes setting attributes for the title font, footnote font, margins, and rule lines in the tables.

The program also adds information to the title and footnote statements through simple macro programming statements.

Program

 
proc template;

Define a style and designate its storage location.
  define style marketing / store=sasuser.templat;

Inherit all the styles from STYLES.PRINTER.
    parent=styles.printer;

Modify several of the font settings defined in STYLES.PRINTER. Change TitleFont2, TitleFont, headingFont, and docFont. Keep the settings for the rest the same as in STYLES.PRINTER.
    replace fonts
          / 'TitleFont2' = ("Times Roman",12pt,Bold)
            'TitleFont' = ("Times Roman",14pt,Bold)
            'StrongFont' = ("Times Roman",10pt,Bold)
            'EmphasisFont' = ("Times Roman",10pt
,Italic)
            'FixedEmphasisFont' = ("Courier",9pt
,Italic)
            'FixedStrongFont' = ("Courier",9pt,Bold)
            'FixedHeadingFont' = ("Courier",9pt,Bold)
            'BatchFixedFont' = ("SAS Monospace,
                                Courier",6.7pt)
            'FixedFont' = ("Courier",9pt)
            'headingEmphasisFont' = ("Times Roman",
                                    11pt,Bold Italic)
            'headingFont' = ("Times Roman",12pt,Bold)
            'docFont' = ("Times Roman",12pt);

Modify the background color of the headers (bgH). Keep the other colors the same as in STYLES.PRINTER.
    replace color_list
         / "Change background to undefined"
           'link' = blue
           'bgH' = _undef_
           'fg' = black
           'bg' = _undef_;

Change all margin settings of the document.
    replace Body from Document
            "Change margins"
          / bottommargin = 1in
            topmargin = 1in
            rightmargin = 1in
            leftmargin = 1in;

Assign a different font to the footer than the TitleFont used in STYLES.PRINTER.
    style SystemFooter from TitlesAndFooters
          "Controls system title text."
         / font = Fonts('EmphasisFont'),

Place only row rules in the tables.
    style table from table
        / rules=rows;
  end;
run;

Suppress the date and page number.
options nodate nonumber;

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:
eportsexample310b.rtf'

Apply a style to the RTF output.
              style=marketing

Suppress the automatic insertion of new pages at the start of each procedure.
              startpage=no;

proc format;
  picture pctfmt (default=7) low-high='009.9%';
run;

%let dsid=%sysfunc(open(work.custresp,i));
%let nresps=%sysfunc(attrn(&dsid,nlobs));
%let rc=close(&dsid);

Define a macro variable whose value will be inserted in the title.
%let companyname=Great Electronics Everyday;

Define a macro variable that equals the formatted value of today’s date.
%let today=%sysfunc(date(),worddate.);

Specify the character that indicates to ODS that what follows the character are style attributes and formatting instructions. Select a character that you know will not be a character value in your data.
ods escapechar='^';

Insert an image in the first title line.
title '^S={preimage="c:
eportsxyz.jpg"}';

title2 "Customer Survey Results for

Italicize the value of the macro variable COMPANYNAME.
       ^S={font_style=italic}&companyname";


title3 "&nresps Respondents";

Insert today’s date in the first footnote line.
footnote "Report Prepared &today";
footnote2 "83872 West Lake Road  Townville, CA 
 99999";
footnote3 "www.xyzmarketingconsultants.com
          (999)555-5555";

proc tabulate data=custresp;
  var factor1-factor4 customer;
  table factor1='Cost'
        factor2='Performance'
        factor3='Reliability'
        factor4='Sales Staff',
        (n='Count'*f=7.
        pctn<customer>='Percent'*f=pctfmt.)
      / box={label='Factors Influencing the Decision
             to Buy'
             style={font_size=12pt cellwidth=2in}};
run;

proc tabulate data=custresp;
  var source1-source3 customer;
  table source1='TV/Radio'
        source2='Internet'
        source3='Word of Mouth',
       (n='Count'*f=7.
        pctn<customer>='Percent'*f=pctfmt.)
      / box={label='Source of Company Name'
        style={font_size=12pt cellwidth=2in}};
run;
proc tabulate data=custresp;
  var website store;
  table website='Website'
         store='Store',
         (sum='Total Visits'*f=7.
         mean='Average Visits Per Customer'*f=8.1)
       / box={label='Visits Resulting in Sales'
         style={font_size=12pt cellwidth=2in}};
run;

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

Send subsequent output to the LISTING destination.
ods listing close;


A Closer Look

Learning More about ODS Styles

A discussion of defining styles is beyond the scope of this book. The purpose of this example is to show you that it’s possible to design a style that you can define once and reuse so that your reports have a uniform appearance.

There are many ways to achieve the look of this report. Some of the attributes defined in the MARKETING style could have been done with inline formatting or with STYLE= options in PROC TABULATE. The opposite is also true. For example, you could modify the SystemTitle style that is inherited from STYLES.PRINTER to place the image, which is the company logo, ahead of the title.

(NOTE: This example did not include this feature because it has three title statements. Putting the image in the SystemTitle style would insert the logo ahead of each of the three TITLE statements. Again, there are additional ways around this problem, but discussion of these is beyond the scope of this book.)

When you intend to use the same attributes over and over for style elements in your report, it might be more efficient to design and save your own style. For attributes that you infrequently need to modify, it is more efficient to add the attributes to your PROC steps or to use inline formatting.

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

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