Chapter Contents

Previous

Next
The TEMPLATE Procedure

Example 4: Creating a Stand-alone Style Definition


PROC TEMPLATE features:
DEFINE STYLE statement
STYLE statement
BACKGROUND=
BORDERCOLORDARK=
BORDERCOLORLIGHT=
BORDERWIDTH=
CELLSPACING=
FONT_FACE=
FONT_SIZE=
FONT_STYLE=
FONT_WEIGHT=
FOREGROUND=
DEFINE TABLE statement
CLASSLEVELS= table attribute
DYNAMIC statement
MVAR statement
DEFINE COLUMN statement
BLANK_DUPS=
GENERIC=
HEADER=
STYLE=
DEFINE FOOTER statement
TEXT statement
Other ODS features:
ODS HTML statement
ODS LISTING statement
FILE statement with ODS= option
PUT statement with _ODS_ argument
Data set: GRAIN_PRODUCTION
Format: $CNTRY.

This example creates a style definition that is not based on any other style definition. In general, when you create a style definition, you are likely to base it on one of the definitions that SAS Institute provides (see Modifying the Default Style Definition for the HTML Destination). However, this example is provided to show you some of the basics of creating a style definition.

It is important to understand that by default, certain table elements are rendered with certain style elements. For instance, unless you specify a different style element with the STYLE= attribute, ODS renders SAS titles with the systemtitle style element. Similarly, unless you specify otherwise, ODS renders headers with the header style element. (For information of what each style element does, see What Is the Default Style Definition Like?.)


Program
 Note about code
proc template;
   define style newstyle;
      style cellcontents /
         background=blue
         foreground=white
         font_face="arial, helvetica"
         font_weight=medium
         font_style=roman
         font_size=4;
 Note about code
      style header /
         background=very light blue
         foreground=blue
         font_face="arial, helvetica"
         font_weight=bold
         font_style=roman
         font_size=5;
 Note about code
     style systemtitle /
         background=white
         foreground=red
         font_face="arial, helvetica"
         font_weight=bold
         font_style=italic
         font_size=6;
 Note about code
     style footer from systemtitle /
         font_size=3;
 Note about code
     style table /
         cellspacing=5
         borderwidth=10
         bordercolorlight=very light blue
         bordercolordark=blue;
 Note about code
   end;
run;
 Note about code
proc template;
   define table table1;
 Note about code
   mvar sysdate9;
 Note about code
   dynamic colhd;
 Note about code
   classlevels=on;
 Note about code
   define column char_var;
      generic=on;
      blank_dups=on;
      header=colhd;
      style=cellcontents;
   end;
 Note about code
   define column num_var;
      generic=on;
      header=colhd;
      style=cellcontents;
   end;
 Note about code
   define footer table_footer;
      text 'Prepared on ' sysdate9;
   end;
 Note about code
   end;
run;
 Note about code
ods listing close;
 Note about code
ods html body='newstyle-body.htm'
         style=newstyle;
 Note about code
   title 'Leading Grain Producers';
   title2 'in 1996';
 Note about code
data _null_;
   set grain_production;
   where type  in ('Rice', 'Corn') and year=1996;
 Note about code
   file print ods=(
        template='table1'
 Note about code
        columns=(
           char_var=country(generic=on format=$cntry.
                    dynamic=(colhd='Country'))
           char_var=type(generic dynamic=(colhd='Year'))
           num_var=kilotons(generic=on format=comma12.
                   dynamic=(colhd='Kilotons'))
           )
        );
 Note about code
   put _ods_;
run;
 Note about code
ods html close;
ods listing;


HTML Output

HTML Output Produced with a New Style Definition
You can use the colors and fonts to confirm that SAS titles use the systemtitle style element, that column headers use the header style element, that the footer uses the table-footer style element, and that the contents of both character and numeric cells use the cellcontents style element. Use the width of the table border, the border colors, and the spacing between cells to confirm that the table itself is rendered with the table style element. [HTML Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.