TEMPLATE Procedure: Creating a Style Template

Concepts: Styles and the TEMPLATE Procedure

Terminology

For more definitions of terms used in this section, see Terminology: TEMPLATE Procedure.
child
within a dimension hierarchy, a descendant in level n-1 of a member that is at level n. For example, if a Geography dimension includes the levels Country and City, then Bangkok would be a child of Thailand, and Hamburg would be a child of Germany.
parent
within a dimension hierarchy, the ancestor in level n of a member in level n-1. For example, if a Geography dimension includes the levels Country and City, then Thailand would be the parent of Bangkok, and Germany would be the parent of Hamburg. The parent value is usually a consolidation of all of its children's values.

Viewing the Contents of a Style

To view the contents of a style, use the SAS windowing environment, the command line, or the TEMPLATE procedure.
  • Using the SAS Windowing Environment
    1. In the Results window, select the Results folder. Right-click and select Templates to open the Templates window.
    2. Double-click Sashelp.Tmplmst to view the contents of that directory.
    3. Double-click Styles to view the contents of that directory.
  • Using the Command Line
    1. To view the Templates window, submit this command in the command line:
      odstemplates
      The Templates window contains the item stores Sasuser.Templat and Sashelp.Tmplmst.
    2. Double-click an item store, such as Sashelp.Tmplmst, to expand the list of directories where ODS templates are stored. The templates that SAS provides are in the item store Sashelp.Tmplmst.
    3. To view the styles that SAS provides, double-click theStyles item store.
    4. Right-click the style, such as Journal, and select Open. The style template is displayed in the Template Browser window.
  • Using the TEMPLATE Procedure
    1. Submit this code to view the contents of the default HTML style that SAS supplies.
      proc template;
      source styles.htmlblue;
      run;
    2. View any of the SAS styles by specifying STYLES.style-template in the SOURCE statement. The SAS styles are in the Sashelp.Tmplmst item store.

Working with Styles

Finding and Viewing the Default Style for ODS Destinations

The default styles for the ODS output destinations are stored in the Styles item store in the template store Sashelp.Tmplmst, along with the other styles that are supplied by SAS. You can view the styles from the Templates window, or you can submit this PROC TEMPLATE step to write the style to the SAS log:
proc template;
   source styles.template-name;
run;
The following table lists the ODS destinations and their default styles:
Destination Category Table
Destination
Default Style Name
LISTING
Listing
HTML
HTMLBlue
MARKUP Language Tagsets
Default
PRINTER
Printer for PDF and PS, monochromePrinter for PCL
RTF
RTF

Modifying Style Elements in the Default Style for HTML and Markup Languages

When you work with styles, it is often more efficient to modify a SAS style than to write a completely new style. Using the CLASS Statement shows you how to modify the default style.
To customize the style for use at a specific site, it is helpful to know what each style element in the style specifies. For a list of the default HTML and markup languages style elements, see ODS Style Elements.

ODS Styles with Graphical Style Information

SAS provides ODS styles that incorporate graphical style information. These styles use a number of style attributes that are used by other style elements, but they also use several style attributes that are unique to graph styles. For example, use the STARTCOLOR= style attribute and the ENDCOLOR= style attribute to produce a gradient effect that gradually changes from the starting color to the ending color in a specified element. When either the STARTCOLOR= style attribute or the ENDCOLOR= style attribute, but not both, is specified, then the style attribute that was not specified is transparent when the TRANSPARENCY= style attribute is being used. In Defining a Table and Graph Style, only the ENDCOLOR= style attribute is specified. Therefore, the starting color is transparent.
The TRANSPARENCY= style attribute is another style attribute that is unique to graph styles. With transparency, specify the level of transparency (from 0.0 to 1.0) to indicate the percentage of transparency (0 to 100 %) for the graph element. While you can use the BACKGROUNDIMAGE= style attribute in other style elements to stretch an image, in graph styles, you can also use the IMAGE= style attribute to position or tile an image.
With graph styles, elements, or templates, you can also combine images and colors to create a blending affect. The blending works best when you use a gray-scale image with a specified color. Blending is done in these style elements: GraphLegendBackground, GraphCharts, GraphData#, GraphFloor, and GraphWalls. To blend, specify a color using the BACKGROUNDCOLOR= or COLOR= style attribute and specify an image using the BACKGROUNDIMAGE= or IMAGE= style attribute.
Note: When using the GraphData# style element, you can use the COLOR= style attribute, but not the BACKGROUNDCOLOR= style attribute to specify a color value.
See Style Attributes Tables for a complete listing of style attributes. For a complete list of style elements see ODS Style Elements.
In addition to using defined ODS styles, you can also modify an existing style or create an entirely new style using the new graph style elements. Defining a Table and Graph Style describes how a defined ODS style was generated.
See Viewing the Contents of a Style for information about viewing the code for the ODS styles that are delivered with SAS.

Understanding Styles, Style Elements, and Style Attributes

To help you become familiar with styles, style elements, and style attributes, look at the relationship between them. The following program creates a style, Concepts.Style. The diagram that follows the program shows the relationship between the style, the style elements, and the style attributes.
proc template;
   define style concepts.style;
      style celldata /
         fontfamily="roman, arial"
         color=blue
         fontweight =bold
         "dark"=black;
      style cellemphasis from celldata /
         color=celldata("dark")
         borderspacing=10;
   end;
run;
Diagram of a Style, Including Style Elements and Style Attributes
Diagram of a Style, Including Style Elements and Style Attributes
The following list corresponds to the numbered items in the preceding diagram:
Note: For a list of the default style elements used for HTML and markup languages and their inheritance, see ODS Style Elements.
1 Concepts.Style is a style. Styles describe how to display presentation aspects (color, font, font size, and so on) of the output for an entire SAS job. A style determines the overall appearance of the ODS documents that use it. Each style consists of style elements. Styles are created with the DEFINE STYLE Statement. New styles can be created independently or from an existing style. You can use the PARENT= Statement to create a new style from an existing style.
2 CellData and CellEmphasis are style elements. A style element is a collection of style attributes that apply to a particular part of the output for a SAS program. For example, a style element might contain instructions for the presentation of column headings or for the presentation of the data inside table cells. Style elements might also specify default colors and fonts for output that uses the style. Style elements exist inside of styles and are defined by the STYLE Statement.
Note: For a list of the default style elements used for HTML and markup languages and their inheritance, see ODS Style Elements.
3 The following are style attribute-value pairs:
  • fontfamily="roman, arial"
  • color=blue
  • fontweight=bold
  • "dark"=black
  • color=celldata("dark")
  • borderspacing=10
Style attributes specify a value for one aspect of the presentation. For example, the COLOR= attribute specifies the value blue for the foreground color of a table, and the FONTFAMILY= attribute specifies the values roman and arial as the font to use. Style attributes exist within style elements and can be supplied by SAS or be user-defined. FONTFAMILY=, COLOR=, FONTWEIGHT=, and BORDERSPACING= are style attributes supplied by SAS. For a list of style attributes supplied by SAS, see Style Attributes Tables .
4 "Dark" is a user-defined style attribute. It specifies to substitute the value black whenever the value "dark" is specified.
5 The value celldata("dark") is a style reference. Style attributes can be referenced with style references. This style reference specifies that PROC TEMPLATE go to the CellData style element and use the value that is specified for the "dark" style attribute. See style-reference for more information about style references.

Understanding Inheritance

Overview

Inheritance can be initiated by the PARENT= statement or the FROM= option in the STYLE statement.
The PARENT= statement specifies that PROC TEMPLATE copy all of the style elements from the parent style to the new child style. The style elements are used in the new template unless the new template has style elements that overrides them.
The FROM= option specifies that PROC TEMPLATE copy all of the style attributes from the parent style element to the specified child style element.

Inheritance Between Styles

Inheritance between styles is initiated by the PARENT= option, and involves the following process:
  1. When the PARENT= statement is specified, style elements in the parent style are copied into the new style. This copying occurs before any inheritance can occur within the new style.
  2. If there is a like-named style element within the child style that does not have a FROM option specified, then the style element from the child style overrides the style element from the parent style.
  3. If there is a like-named style element within the child style that does have the FROM option specified, then the child style element absorbs the style attributes from the parent style element. If there are like-named style attributes in the two style elements, then the style attributes from the child style element are used.
The following code shows an example of inheritance between two styles:
Original Code for Creating Style2
define style style1;
    style fonts /
        "docfont" = ("Arial", 3)
        "tablefont" = ("Times", 2);
     style output /
        cellpadding = 5
        borderspacing = 0
        font = fonts("docfont");
    style table from output /
        borderspacing = 2
        font = fonts("tablefont");
     style header /
         backgroundcolor=white
         color=blue
         fontfamily="arial, helvetica"
         fontweight=bold;
 end;

define style style2;
   parent = style1;
     style fonts from fonts /
        "docfont" = ("Helvetica", 3);
     style table from table /
        borderspacing = 4;
     style header /
         fontstyle=roman
         fontsize=5;
end;
The Style2 style from the previous code could also be written this way:
Expanded Version of Style2
define style style2;
   style fonts/
      "docfont" = ("Helvetica", 3)
      "tablefont" = ("Times", 2);
   style output /
      cellpadding = 5
      borderspacing = 0
      font = fonts("docfont");
   style table from output /
      borderspacing=4
      font = fonts("tablefont");
   style header /
         fontstyle=roman
         fontsize=5;
end;

Inheritance Between Style Elements

The FROM option on a STYLE statement is used to initiate inheritance from another style element. The style element referenced by the FROM option can exist in either the current style or the parent style (if a parent template is specified using the PARENT= statement).
For example, in both the Original Code for Creating Style2 and the Expanded Version of Style2 the Table style element, which is created with the style table from output / ..., statement, ends up with the following style attributes:
  • cellpadding= 5
  • borderspacing= 4
  • font=fonts("tablefont")

Understanding Style References

A style reference references a style attribute in a style element. The style element can exist either in the current style or in the parent style.
For example, suppose that you create a style element named DataCell that uses the COLOR= and BACKGROUNDCOLOR= style attributes:
style datacell / backgroundcolor=blue
                 color=white;
To ensure that another style element, NewCell, uses the same background color, use a style reference in the NewCell element, like this:
style newcell / backgroundcolor=datacell(backgroundcolor);
The style reference datacell(backgroundcolor) indicates that the value for the style attribute BACKGROUNDCOLOR= of the style element named DataCell should be used.
Similarly, suppose that you create a style element named HighLighting that defines three style attributes:
style highlighting /
   "go"=green
   "caution"=yellow
   "stop"=red;
You can then define a style element named Messages that references the colors that are defined in the HighLighting style element:
style messages;
   "note"=highlighting("go")
   "warning"=highlighting("caution")
   "error"=highlighting("stop");
Because you used style references, multiple style elements can use the colors defined in the HighLighting style element. If you change the value of go to blue in the HighLighting style element, then every style element that uses the style reference highlighting("go") will use blue instead of green.
In the following code, the FONT= style attribute in the Output style element is defined in terms of the Fonts style element. The value fonts("docfont") tells PROC TEMPLATE to go to the last instance of the style element named Fonts and use the value for the style attribute DocFont.
The FONT= style attribute in the Table style element is also defined in terms of the Fonts style element. The value fonts("tablefont") tells PROC TEMPLATE to go to the last instance of the style element named Fonts and use the value for the style attribute TableFont.
Program with Unresolved Style References
define style style1;
    style fonts /
        "docfont" = ("Arial", 3)
        "tablefont" = ("Times", 2);
     style output /
        cellpadding = 5
        borderspacing = 0
        font = fonts("docfont");
    style table from output /
        borderspacing = 2
        font = fonts("tablefont");
     style header /
         backgroundcolor=white
         color=blue
         fontfamily="arial, helvetica"
         fontweight=bold;
 end;

define style style2;
   parent = style1;
     style fonts from fonts /
        "docfont" = ("Helvetica", 3);
     style table from table /
        borderspacing = 4;
     style header /
         fontstyle=roman
         fontsize=5;
end;
When you submit the code in SAS, the output is created as if you submitted the following program. Notice that in the Output style element, the style reference resolves to ("helvetica", 3), not ("Arial", 3). This is because the "DocFont" user-supplied style attribute in the Style2 style overrides the like-named style attribute in the Style1 style.
Program with Unresolved Style References
define style style1;
    style fonts /
        "docfont" = ("Arial", 3)
        "tablefont" = ("Times", 2);
     style output /
        cellpadding = 5
        borderspacing = 0
   /*** Resolved from "docfont" in Style2***/
        font = fonts("helvetica", 3);
    style table from output /
        borderspacing = 2
   /*** Resolved from "tablefont" in Style1***/
        font = fonts("Times", 2);
     style header /
         backgroundcolor=white
         color=blue
         fontfamily="arial, helvetica"
         fontweight=bold;
 end;

define style style2;
   parent = style1;
     style fonts from fonts /
        "docfont" = ("Helvetica", 3);
     style table from table /
        borderspacing = 4;
     style header /
         fontstyle=roman
         fontsize=5;
end;

Using the FROM Option

The FROM option is used with a style element in order to inherit from another style element. If you omit the FROM option, then you can have an incomplete style element in the child style.
For example, in the following SAS program, the style Concepts.Style2 inherits all of its style elements and style attributes from the style Concepts.Style1. However, the instance of the style element Colors in Concepts.Style2 overrides the instance of Colors in Concepts.Style1. This is because there is no FROM option in the STYLE statement that creates Colors in Concepts.Style2. Therefore, Colors has one style attribute: "dark"=dark blue.
When you run the program, the only style references to Color that resolve are references that refer to the "dark" style attribute. Style references in Concepts.Style1 and Concepts.Style2 such as colors("fancy") and colors("medium") do not resolve because they refer to attributes that were not copied into the current instance of the Colors style element. The resulting output is Output Created without the FROM Option.
To correct this, in the following program, you can add the FROM option to the STYLE statement that creates the Colors style element in Concepts.Style2:
style colors from colors /
   "dark"=dark blue;
Note: In the following code, Concepts is a folder that is created in Templatesthen selectSasuser.Templat. Style1 is a template that is created in the Concepts folder.
Creating the Colors Style Element without the FROM Option
proc template;
   define style concepts.style1;
      style colors /
         "default"=white
         "fancy"=very light vivid blue
         "medium"=red ;
      style celldatasimple /
         fontfamily=arial
         backgroundcolor=colors("fancy")
         color=colors("default");
      style celldataemphasis from celldatasimple /
         color=colors("medium")
         fontstyle=italic;
      style celldatalarge from celldataemphasis /
         fontweight=bold
         fontsize=3;
   end;
run;

proc template;
   define style concepts.style2;
      parent=concepts.style1;
      style colors /
         "dark"=dark blue;
      style celldataemphasis from celldataemphasis /
         backgroundcolor=white;
      style celldatasmall from celldatalarge /
         fontsize=5
         color=colors("dark")
         backgroundcolor=colors("medium");
   end;
run;
For the complete SAS code that created the following output, see the version of the code without the FROM option in Using the FROM option.
Output Created without the FROM Option
Output Created without the FROM Option
For the complete SAS code that created the following output, see the version of the code with the FROM option in Using the FROM option.
Output Created with the FROM Option
Output Created with the FROM Option

Inheritance Compatibility across Versions

In most cases, an ODS style element or style that was created in a previous version of SAS will still be compatible with later versions of SAS. However, beginning with SAS 9.2, style inheritance is completely expanded before style element inheritance takes place. This change can cause discrepancies between the output a program creates in a previous version of SAS and the output that same program creates in SAS 9.2.
The following program creates different output depending on whether it is run in SAS 9.2 or in a previous version of SAS. In SAS 9.2, the yellow background that CellDataEmphasis has in Concepts.Style2 is passed to CellDataLarge and CellDataSmall. However, in previous versions of SAS, the yellow background is not passed to CellDataLarge and CellDataSmall. For more information about the using the FROM option, see Using the FROM Option.
Note: In the following code, Concepts is a folder that is created in Templatesthen selectSasuser.Templat. Style1 is a template that is created in the Concepts folder.
proc template;
   define style concepts.style1;
      style celldatasimple /
         fontfamily=arial
         backgroundcolor=very light vivid blue
         color=white;
      style celldataemphasis from celldatasimple /
         color=red1 
         fontstyle=italic;
      style celldatalarge from celldataemphasis /
         fontweight=bold
         fontsize=5;
   end;
run;

proc template;
   define style concepts.style2;
      parent=concepts.style1;
      style celldataemphasis from celldataemphasis3/ 
         backgroundcolor=yellow2; 
      style celldatasmall from celldatalarge /
         fontsize=2;
   end;
run;
The output this program creates when you run it in a previous version of SAS is different from the output the program creates in SAS 9.2 and beyond. This is because, when you change the value of the COLOR= attribute in CellDataEmphasis from red (1) to yellow (2), the change affects only style elements that inherit from CellDataEmphasis in Concepts.Style2. Within Concepts.Style2, there are no style elements that inherit from CellDataEmphasis (3). Therefore, only CellDataEmphasis in Concepts.Style2 has yellow text. Beginning with SAS 9.2, all style elements in parent style definitions also pick up the color change.
For the complete SAS code that created this output, see the SAS 9.1 version of the code in Inheritance Compatibility Across SAS Versions.
SAS 9.2 Output
SAS 9.2 Output
SAS 9.1 Output
SAS 9.1 Output