TEMPLATE Procedure: Creating a Style Template (Definition) |
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.
To view the Templates window, submit this command in the command line:
odstemplatesThe Templates window contains the item stores Sasuser.Templat and Sashelp.Tmplmst.
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.
To view the styles that SAS provides, double-click the Styles item store.
Right-click the style, such as Journal, and select Open. The style template is displayed in the Template Browser window.
Working with Styles |
The default styles for the ODS output destinations are stored in the STYLES directory in the template store Sashelp.Tmplmst, along with the other styles that are supplied by SAS. You can view the styles from the TEMPLATE 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:
Destinations | Default Style Name |
---|---|
LISTING | Listing |
HTML | Default |
MARKUP Language Tagsets | Default |
PRINTER | Printer for PDF and PS, monochromePrinter for PCL |
RTF | RTF |
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 graph style information. These styles utilize 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 grayscale 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 and Their Values 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") cellspacing=10; end; run;
Diagram of a Style, Including Style Elements and Style Attributes
The following list corresponds to the numbered items in the preceding diagram:
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 is composed 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. | |
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. | |
The following are style attribute-value pairs: 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 CELLSPACING= are style attributes supplied by SAS. For a list of style attributes supplied by SAS, see Style Attributes and Their Values. | |
"Dark" is a user-defined style attribute. It specifies to substitute the value black whenever the value "dark" is specified. | |
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 |
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 is initiated by the PARENT= option, and involves the following process:
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.
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.
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 cellspacing = 0 font = fonts("docfont"); style table from output / cellspacing = 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 / cellspacing = 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 cellspacing = 0 font = fonts("docfont"); style table from output / cellspacing=4 font = fonts("tablefont"); style header / fontstyle=roman fontsize=5; end;
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 Style2 style and the expanded version the Table style element, which is created with the style table from output / ... statement, ends up with the following style attributes:
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 cellspacing = 0 font = fonts("docfont"); style table from output / cellspacing = 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 / cellspacing = 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 Resolved Style References define style style1; style fonts / "docfont" = ("Arial", 3) "tablefont" = ("Times", 2); style output / cellpadding = 5 cellspacing = 0 /*** Resolved from "docfont" in Style2***/ font = fonts("helvetica", 3); style table from output / cellspacing = 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 / cellspacing = 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. This can result in an incomplete style element in the child style.
For example, in Program 1 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, 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;
Program 1: 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
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
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.
Program 2: Using Inheritance to Create a New Style Element from a Style Element in the Parent Style proc template; define style concepts.style1; style celldatasimple / fontfamily=arial backgroundcolor=very light vivid blue color=white; style celldataemphasis from celldatasimple / color=red 1 fontstyle=italic; style celldatalarge from celldataemphasis / fontweight=bold fontsize=5; end; run; proc template; define style concepts.style2; parent=concepts.style1; style celldataemphasis from celldataemphasis/ 3 backgroundcolor=yellow; 2 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. This is because, when you change the value of the COLOR= attribute in CellDataEmphasis from red () to yellow (), 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. 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.1 Output
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.