Concepts: Style Definitions and the TEMPLATE Procedure


Viewing the Contents of a Style Definition

To view the contents of a style definition, you can use the SAS windowing environment, the command line, or the TEMPLATE procedure.

  • Using the SAS Windowing Environment

    1. From the SAS Explorer, select

      View Results

    2. In the Results window, select the Results folder. Right click and select Templates to open the Templates window.

    3. Double click on Styles to view the contents of that directory.

    4. Double click on the style definition that you want to view. For example, the Default style definition is the template store for HTML output. Similarly, the RTF style definition is the template store for RTF output.

  • Using the Command Line

    1. To view the Templates window, submit the following command in the command bar:

       odstemplates 

      The Templates window contains the item stores Sasuser.Templat and Sashelp.Tmplmst .

    2. When you double-click an item store, such as Sashelp.Tmplmst , that item store expands to list the directories where ODS templates are stored. The templates that SAS provides are in the item store Sashelp.Tmplmst.

    3. To view the style definitions that SAS provides, double-click the Styles item store.

    4. Right-click the style definition, such as Journal , and select Open. The style definition is displayed in the Template Browser window.

  • Using the TEMPLATE Procedure

    1. Submit the following code to view the contents of the default HTML style definition that SAS supplies .

       proc template;  source styles.default;  run; 
    2. You can view any of the SAS style definitions by specifying the styles. style-definition in the SOURCE statement. The SAS style definitions are in the SASHELP.TMPLMST item store.

The Default Style Definition for HTML and Markup Languages

Where Is the Default Style Definition for HTML and Markup Languages?

The default style definition for the HTML and markup languages destinations are stored in STYLES.DEFAULT in the template store SASHELP.TMPLMST. You can view the style definition from the TEMPLATE window, or you can submit this PROC TEMPLATE step to write the style definition to the SAS log:

 proc template;  source styles.default;  run; 
Modifying Style Elements in the Default Style Definition for HTML and Markup Languages

When you are working with style definitions, you are more likely to modify a SAS style definition than to write a completely new style definition. Example 3 on page 355 shows you how to modify the default style definition.

When you want to customize the style definition for use at your site, it is helpful to know what each style element in the style definition specifies. For a list of the default HTML and markup languages style elements, see Appendix 4, 'HTML, Printer Family, and Markup Languages Style Elements and Their Inheritances,' on page 651.

Note: The default style definition for the PRINTER destination is stored in STYLES.PRINTER in the template store SASHELP.TMPLMST. Similarly, the default style definition for the RTF destination is stored in STYLES.RTF in the template store SASHELP.TMPLMST.

ODS Styles with Graphical Style Information

SAS provides ODS styles that incorporate graph style information. See 'Viewing the Contents of a Style Definition' on page 319 for information about viewing the code for the ODS styles delivered with SAS. 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. Example 4 on page 361 describes how a defined ODS style was generated. See 'Style Attributes and Their Values' on page 292 for a complete listing of style attributes. For a complete list of style elements see Appendix 4, 'HTML, Printer Family, and Markup Languages Style Elements and Their Inheritances,' on page 651.

Note: The graph styles (attributes and elements) are at the bottom of the style attributes and style elements tables.

While graph styles utilize a number of attributes that are also used by other styles generated with PROC TEMPLATE, several attributes are unique to graph styles. For example, you can use STARTCOLOR and ENDCOLOR to produce a gradient effect that gradually changes from the starting color to the ending color in a specified element. When only either a STARTCOLOR or ENDCOLOR, but not both, is specified, then the attribute that was not specified is transparent when TRANSPARENCY is being used. In Example 4 on page 361, only an ENDCOLOR is specified; therefore, the starting color is transparent.

TRANSPARENCY is another attribute unique to graph styles. With transparency, you can 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 BACKGROUNDIMAGE in other styles to stretch an image, in graph styles you can also use IMAGE to position or tile an image.

With graph styles 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 can be done in the following elements: GraphLegendBackground, GraphCharts, GraphData#, GraphFloor, and GraphWalls. To blend, specify a color using the BACKGROUND or FOREGROUND attribute and specify an image using the BACKGROUNDIMAGE or IMAGE attribute.

Note: When using the GraphData# element, you can use the FOREGROUND attribute, but not the BACKGROUND attribute to specify a color value.

About Style Definition Inheritance and Style Element Inheritance

Definitions

To help you become familiar with style definition inheritance and style element inheritance, let's review the definitions of a style definition and a style element.

style definition

describes how to display the presentation aspects (color, font, font size , and so on) of the output for an entire SAS job. A style definition determines the overall appearance of the documents that use it. Each style definition is composed of style elements.

style element

is a collection of style attributes that apply to a particular part of the output for a SAS job. For example, a style element may contain instructions for the presentation of column headers or for the presentation of the data inside cells . Style elements may also specify default colors and fonts for output that uses the style definition. Each style attribute specifies a value for one aspect of the presentation. For example, the BACKGROUND= attribute specifies the color for the background of an HTML table, and the FONT_STYLE= attribute specifies whether to use a Roman, a slant, or an italic font.

When you use PROC TEMPLATE to create style definitions, it is important to understand inheritance. There are two types of inheritance:

style definition inheritance

  • specifies that the child style definition receives all of the style elements and attributes and statements that are specified in the parent's definition. They are used in the new definition unless the new definition overrides them.

style element inheritance

  • specifies that the child style element receives all of the elements and their attributes that are specified in another style definition. They are used in the new style definition unless the new definition overrides them. Each style attribute specifies a value for one aspect of the presentation. For example, a style element may contain instructions for the presentation of column headers or for the presentation of the data inside cells. Style elements may also specify default colors and fonts for output that uses the style definition.

Note: For a list of the default style elements used for HTML and markup languages and their inheritance, see Appendix 4, 'HTML, Printer Family, and Markup Languages Style Elements and Their Inheritances,' on page 651.

How to Determine Style Definition Inheritance

A style definition determines the overall appearance of the documents that use it. Each style definition is composed of style elements. A style definition is created with the DEFINE STYLE statement and its substatements and attributes.

The PARENT= attribute, used with the DEFINE STYLE statement, determines style definition inheritance. When you specify a parent for a style definition, all the style elements, attributes, and statements that are specified in the parent's definition are used in the new definition unless the new definition overrides them.

How to Determine Style Element Inheritance

The STYLE and REPLACE statements, used with the DEFINE STYLE statement, determine style element inheritance. They augment or override the attributes of a particular style element. You can use the STYLE statement in either a style definition that has no parent or a style definition that has a parent. However, you can use the REPLACE statement only in a style definition that has a parent.

Creating a Style Definition with No Parent, Using Style Element Inheritance

This section explains style definition inheritance and style element inheritance, beginning with the simpler case of style element inheritance in a style definition that has no parent and progressing to more complicated cases. The focus here is on PROC TEMPLATE and the DEFINE STYLE statement, so only the PROC TEMPLATE code that creates the style definitions appears in the text. However, in order to produce the HTML output that is shown here, it is necessary to create a customized table and to bind that table to a data set. The complete code that produces each piece of output is in 'Programs that Illustrate Inheritance' on page 622.

  • Creating a Style Element in a Style Definition

    Use a DEFINE STYLE statement to create each style element in the style definition. The following PROC TEMPLATE step creates the style definition, concepts.style1 , that contains one style element, celldatasimple .

    Example Code 9.1: Creating a Style Definition with One Style Element

    start example

    This style element contains the following style attributes:

    • Arial font

    • light blue background

    • white foreground.

     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;     end;  run; 
    end example
     

    The style element celldatasimple does not inherit any attributes from any other element. It is simply created with the three attributes shown. All other attributes are set by the browser when a table is displayed in HTML with this style definition. The following HTML output uses the following style definition.

    The style definition for this HTML output uses contains only one style element: celldatasimple . All three columns use this style element. celldatasimple contains the following style attributes:

    FONT_FACE=arial

    BACKGROUND=very light vivid blue

    FOREGROUND=white.

    click to expand
    Display 9.3: Using a Style Definition with One Style Element

  • Creating a Second Style Element in a Style Definition

    You can create a second style element in a style definition either independently of any other style element or from an existing style element.

    Suppose that you want an additional style element that emphasizes the data for cells by using an italic font. The style element uses the same font and background color as celldatasimple , but it uses blue instead of white for the foreground color. Program

     [1] 
    shows you how you can create the new style element independently. Alternatively, you can create celldataemphasis from celldatasimple as shown in program
     [2]. 

    Example Code 9.2: Program 1-Creating a Second Style Element Independently or from an Existing Style Element

    start example

    The PROC TEMPLATE steps in the following code produces identical results. In both cases, celldatasimple contains the following style attributes:

    • FONT_FACE=arial

    • BACKGROUND=very light vivid blue

    • FOREGROUND=white.

    celldataemphasis contains the following style attributes:

    • FONT_FACE=arial (inherited from celldatasimple )

    • BACKGROUND=very light vivid blue (inherited from celldatasimple )

    • FOREGROUND=blue (modified in celldataemphasis )

    • FONT_STYLE=italic (added in celldataemphasis ).

    [1]  
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis /           font_face=arial           background=very light vivid blue           foreground=blue           font_style=italic;     end;  run; 
    end example
     

    Example Code 9.3: Program 2-Creating a Second Style Element from an Existing Style Element

    start example
    [2]  
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;     end;  run; 
    end example
     

    The following HTML output uses the style definition concepts.style1 .

    The style definition that this HTML output contains two style elements: celldatasimple and celldataemphasis . The columns for Country and Kilotons use celldatasimple . The column for grain uses celldataemphasis .

    click to expand
    Display 9.4: A Style Definition with Two Style Elements

  • Comparing the Two Methods

    Although the two PROC TEMPLATE steps above produce identical HTML output, there is an important difference between them that is illustrated by programs

     [3] 
    and
     [4]. 

    Program

     [3] 
    below does not use style element inheritance. celldataemphasis is created independently of celldatasimple , so a change to celldatasimple does not affect celldataemphasis . Even if you change the STYLE statement that creates celldatasimple so that the font is Times, then the program still creates celldataemphasis with Arial as the font.

    However, in program

     [4] 
    , if you change the font for celldatasimple from Arial to Times , then celldataemphasis does use the Times font. This is because the change to FONT_FACE= is passed to celldataemphasis , which inherits all the attributes from celldatasimple .

    Example Code 9.4: Program 3-Changing the Font in Only One Style Element

    start example
    [3]  
     proc template;    define style concepts.style1;       style celldatasimple  /   font_face=times   background=very light vivid blue          foreground=white;       style celldataemphasis /   font_face=arial   background=very light vivid blue          foreground=blue          font_style=italic;  end; 
    end example
     

    Example Code 9.5: Program 4-Changing the Font in the Parent and Child Style Elements

    start example
    [4]  
     proc template;    define style concepts.style1;       style celldatasimple   /   font_face=times   background=very light vivid blue          foreground=white;       style celldataemphasis from celldatasimple /          foreground=blue          font_style=italic;  end; 
    end example
     
  • Output For Comparing The Two Methods

    The following HTML output uses the style definition created by program

     [3] 
    .

    Here, the font in the style element celldatasimple , which is used for the first and third columns in the HTML output, has changed from Arial to Times. However, celldataemphasis , which is used for the second column, still uses the Arial font because it does not inherit any attributes from celldatasimple .

    click to expand
    Display 9.5: Changing the Font in Only One Style Element

    The following HTML output uses this style definition created by program

     [4]. 

    In this case, the change to the Times font in celldatasimple is inherited by celldataemphasis . Both style elements use the Times font . The only attributes that differbetween the two style elements are attributesthat were explicitly redefined in the definition of celldataemphasis (the FOREGROUND= attribute, which was changed, and the FONT_STYLE= attribute, which was added). The columns for Country and Kilotons use celldatasimple . The column for Grain uses celldataemphasis .

    click to expand
    Display 9.6: Inheriting a Change to a Style Element

  • Adding a Third Style Element

    In this example, a third style element is added to the style definition. This style element further emphasizes the data by using a large, bold, italic font. Again, you can create the new style element from scratch, or you can derive it from either of the other style elements. The following program creates celldatalarge from celldataemphasis :

    Example Code 9.6: Program 5-Creating the Style Element celldatalarge

    start example
    [5]  
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run; 
    end example
     

    The style elements celldatasimple and celldataemphasis have not changed.

    celldatasimple has these attributes:

    • FONT_FACE=arial

    • BACKGROUND=very light vivid blue

    • FOREGROUND=white.

    celldataemphasis has these attributes:

    • FONT_FACE=arial (inherited from celldatasimple )

    • BACKGROUND=very light vivid blue (inherited from celldatasimple )

    • FOREGROUND=blue (modified in celldataemphasis )

    • FONT_STYLE=italic (added in celldataemphasis ).

    The new style element, celldatalarge , has these attributes:

    • FONT_FACE=arial (inherited from celldataemphasis , which inherited it from celldatasimple )

    • BACKGROUND=very light vivid blue (inherited from celldataemphasis , which inherited it from celldatasimple )

    • FOREGROUND=blue (inherited from celldataemphasis )

    • FONT_STYLE=italic (inherited from celldataemphasis )

    • FONT_WEIGHT=bold (added in celldatalarge )

    • FONT_SIZE=5 (added in celldatalarge ).

    The following HTML output uses the new style definition created by program

     [5]. 

    The style definition that this HTML output uses contains three style elements: celldatasimple , celldataemphasis , and celldatalarge . The column for Country uses celldatasimple . The column for Grain uses celldataemphasis. The column for Kilotons uses celldatalarge .

    click to expand
    Display 9.7: Adding the Style Element celldatalarge

    In this case, celldatalarge inherits style attributes from celldataemphasis , and celldataemphasis inherits from celldatasimple . If you change the font in celldatasimple , then the font in the other style elements also changes. If you change the font style or foreground color in celldataemphasis , then the font style or foreground color in celldatalarge also changes. Changes to celldatalarge affect only celldatalarge because no style element inherits from it.

Summary of Style Element Inheritance in a Style Definition with No Parent

The following points summarize style element inheritance in a style definition that does not have a parent:

  • You can create a new style element from any existing style element.

  • The new style element inherits all the attributes from its parent.

  • You can specify additional attributes in the new style definition. The attributes are added to the attributes that the element inherits.

  • You can change the value of an inherited attribute by respecifying it in the definition of the new style element.

Creating a Style Definition with a Parent Using Style Element Inheritance
  • Using One Style Definition to Create Another Style Definition

    Use the PARENT= attribute in a new style definition to inherit an entire style definition.

    This example uses concepts.style1 , which was created in 'Creating a Style Definition with No Parent, Using Style Element Inheritance' on page 323. The following program creates a new style definition, concepts.style2 , which inherits the entire style definition from its parent, concepts.style1 . At this point, the two style definitions are identical:

    Example Code 9.7: Using Style Definition Inheritance to Create a New Style Definition

    start example
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template;     define style concepts.style2;   parent=concepts.style1;   end;  run; 
    end example
     

    You can change the new style definition either independently of any other style definitions with a parent by simply overriding the style elements, or by using a style element from another parent style definition.

Creating a Style Element in a Style Definition with a Parent
  • Creating a New Style Definition with a Parent

    You can control the style definition inheritance with the PARENT= attribute of the DEFINE STYLE statement. When you specify a parent for a style definition, all the style elements, attributes, and statements that are specified in the parent's definition are used in the new definition unless the new definition overrides them.

    In this example, a new style element is added to concepts.style2 . The following program adds celldatasmall , a style element that does not exist in the parent style definition. Its definition is not based on any other style element.

    Example Code 9.8: Creating a Style Element Independently in a Style Definition with a Parent

    start example
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template;     define style concepts.style2;        parent=concepts.style1;        style celldatasmall /           font_face=arial           background=very light vivid blue           foreground=blue           font_style=italic           font_weight=bold           font_size=2;     end;  run; 
    end example
     

    If you look at the attributes for celldatasmall , you can see that they match the attributes for celldatalarge in the parent style definition, except for FONT_SIZE=.

  • Creating a Style Element from a Style Element in a Parent Definition

    Another way to create this new style element, is to create it from celldatalarge . You do this just as you did when you created a style element in a style definition that did not have a parent:

    Example Code 9.9: Creating a New Style Element from a Style Element in the Parent Style Definition

    start example
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template;     define style concepts.style2;        parent=concepts.style1;        style celldatasmall from celldatalarge /           font_size=2;     end;  run; 
    end example
     

    When you specify the FROM option in the STYLE statement of a style definition with a parent, PROC TEMPLATE first searches in the child style definition for the style element that you specify . If no such style element exists, it searches in the parent style definition and continues searching up through the hierarchy of parents. In this case, because no style element called celldatalarge exists in concepts.style2 , PROC TEMPLATE uses the style element from the parent style definition.

  • Comparing the Style Element celldatasmall

    The style definition concepts.style2 that is produced in program

     [6] 
    below is identical to the one that is produced in program
     [7]. 
    In both cases, the style element celldatasmall has these attributes:
    • FONT_FACE=arial (inherited from celldatalarge through celldataemphasis and celldatasimple )

    • BACKGROUND=very light vivid blue (inherited from celldatalarge through celldataemphasis and celldatasimple )

    • FOREGROUND=blue (inherited from celldatalarge through celldataemphasis )

    • FONT_STYLE=italic (inherited from celldatalarge through celldataemphasis )

    • FONT_WEIGHT=bold (inherited from celldatalarge )

    • FONT_SIZE=2 (modified in celldatasmall ).

    Example Code 9.10: Program 6-Creating a Style Element Independently in a Style Definition with a Parent

    start example
    [6]  
     proc template;     define style concepts.style1;        style celldatasimple/           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template;     define style concepts.style2;        parent=concepts.style1;   style celldatasmall   /           font_face=arial           background=very light vivid blue           foreground=blue           font_style=italic           font_weight=bold           font_size=2;   end;  run; 
    end example
     

    Example Code 9.11: Program 7-Creating a New Style Element from a Style Element in the Parent Style Definition

    start example
    [7]  
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template;     define style concepts.style2;        parent=concepts.style1;   style celldatasmall from celldatalarge   /           font_size=2;     end;  run; 
    end example
     

    The following HTML output uses the style definition concepts.style2 .

    The style definition concepts.style2 contains four style elements. The style definition inherits celldatasimple , celldataemphasis , and celldatalarge from the parent style definition, concepts.style1 . The column for Country uses celldatasimple . The column for grain uses celldataemphasis . The first column for Kilotons uses celldatalarge . The fourth style element in the new style definition is celldatasmall . This style element is created in concepts.style2 . It inherits from celldatalarge in concepts.style1 . The fourth column, which repeats the values for Kilotons , uses celldatasmall .

    click to expand
    Display 9.8: Creating a New Style Element from a Style Element in the Parent Style Definition

    Although program

     [6] 
    and program
     [7] 
    above produce the same style definition for concepts.style2 , they will produce different style definitions if you change the definition of celldatalarge in the parent (or the definition of any of the style elements that celldatalarge inherits from). In program
     [6] 
    changes to celldatalarge do not affect celldatasmall because celldatasmall is created independently in the new style definition. It does not inherit from any style element in the parent style definition.

    However, in program

     [7] 
    , changes that you make to celldatalarge in the parent style definition do affect celldatasmall because celldatasmall inherits (and adds to) the attributes of celldatalarge . Similarly, changes to other style elements in the parent style definition do not affect celldatasmall in program
     [6] 
    , but they do affect celldatasmall in program
     [7]. 

    For example, program

     [8] 
    below is based on Creating a New Style Element from a Style Element in the Parent Style Definition on page 331. It changes the font in celldatasimple from Arial to Times. All the other style elements, in both the parent and the child style definitions, inherit this change. The program also changes the foreground color of celldataemphasis to black. The style elements celldatalarge (in the parent style definition) and celldatasmall (in the new style definition) both inherit this foreground color.

    Example Code 9.12: Program 8-Inheriting Changes from Style Elements in the Parent Style Definition

    start example
    [8]  
     proc template;     define style concepts.style1;        style celldatasimple /   font_face=times   background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /   foreground=black   font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template;     define style concepts.style2;        parent=concepts.style1;        style celldatasmall from celldatalarge /           font_size=2;     end;  run; 
    end example
     

    The following HTML output uses the new style definition created by program

     [8]. 

    Changes to the style elements in the parent style definition are passed to style elements that inherit from these elements in both the parent and the child style definitions.

    click to expand
    Display 9.9: Inheriting Changes to the Parent Style Definition

    Creating a new style element in a style definition that has a parent is not very different from creating a new style element in a style definition that does not have a parent. The only difference is that the style element that you specify with FROM in the STYLE statement can be in either the parent or the child style definition.

Modifying Existing Style Elements with a Parent

When you create a new style definition from a parent style definition you can, in addition to adding new style elements, modify existing style elements. There are two ways to do this:

  • change only the style element that you specify by using the STYLE statement

  • change the style element that you specify and all the style elements that inherit from that element by using the REPLACE statement.

The following programs show the results of these methods.

  • Modifying a Style Element by Using the STYLE Statement

    The following program uses the STYLE statement to redefine the style element celldataemphasis in concepts.style2 . It changes the background color to white:

    Example Code 9.13: Redefining a Style Element with the STYLE Statement

    start example
     proc template;    define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;        end;  run;  proc template:    define style concepts.style2;        parent=concepts.style1;        style celldataemphasis from celldataemphasis /           background=white;        style celldatasmall from celldatalarge /           font_size=2;        end;  run; 
    end example
     

    In this case, celldataemphasis in concepts.style2 initially inherits all the attributes of celldataemphasis in concepts.style1 because it is created from this style element. The inherited attributes are

    • FONT_FACE=Arial (which celldataemphasis inherits from celldatasimple )

    • BACKGROUND= very light vivid blue, (which celldataemphasis inherits from celldatasimple )

    • FOREGROUND=white

    • FONT_STYLE=italic.

    The STYLE statement that creates celldataemphasis in concepts.style1 changes the background color to white. The background color is the only difference between the celldataemphasis style elements in concepts.style2 and concepts.style1 .

    But, what about celldatalarge in concepts.style2 ? The celldatalarge style element is not redefined in concepts.style2 . It is defined only in concepts.style1 , where it inherits all the attributes of celldataemphasis . So the question is, from which style definition is celldataemphasis inherited-from the parent style definition ( concepts.style1 ), or from the child style definition ( concepts.style2 )? Is the white background inherited or not?

    The answer is that the white background is not inherited because the STYLE statement that creates celldataemphasis in the concepts.style2 affects only those style elements that inherit from celldataemphasis and that are defined in the new style definition . Because celldatalarge is defined only in concepts.style1 , it does not inherit the changes that are specified in concepts.style2 . Similarly, celldatasmall does not inherit the white background because it inherits the background from celldatalarge . The following HTML output uses this modified version of concepts.style2 :

    A style element that is defined with the STYLE statement in the child style definition does not pass its attributes to style elements that inherit from the like-named style element in the parent style definition. In this case, the change of the background color for celldataemphasis is made in the child style definition. The new background color is not inherited by celldatalarge because although the background is inherited from celldataemphasis , the background is defined in the parent style definition, not the child definition. Nor is the change inherited by celldatasmall , which inherits all of its attributes from celldatalarge and from the parents of celldatalarge , which include celldataemphasis (as defined in the parent style definition) and celldatasimple .

    click to expand
    Display 9.10: Using the STYLE Statement to Alter an Existing Style Element in the Child Style Definition

    Now suppose that you want to pass the white background from celldataemphasis on to celldatalarge even though it is defined only in concepts.style1 ? You can do this by redefining celldatalarge in concepts.style2 with a STYLE statement. This method works well when you are defining only a few style elements.

    Example Code 9.14: Redefining a Style Element without Inheritance

    start example
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;        end;  run;  proc template:     define style concepts.style2;        parent=concepts.style1;        style celldataemphasis from celldataemphasis /           background=white;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;        style celldatasmall from celldatalarge /           font_size=2;        end;  run; 
    end example
     

    In this case, when PROC TEMPLATE processes the STYLE statement that creates celldatalarge , it looks for a style element named celldataemphasis to inherit from. Because there is such a style element in concepts.style2 , PROC TEMPLATE uses that style element. (If there were no such element in concepts.style2 , then PROC TEMPLATE would look for one in concepts.style1 and use that one.) Therefore, celldatalarge inherits the new definition of celldataemphasis , which includes the white background. Similarly celldatasmall , which now inherits from celldatalarge in concepts.style2 , inherits the white background.

  • Modifying a Style Element by Using the REPLACE Statement

    Now suppose that you have a large number of style elements that are inherited from celldataemphasis . It would be time-consuming to redefine all of them in concepts.style2 .

    Fortunately, there is a way to redefine celldataemphasis so that the changes are passed on to style elements that inherit from it. With PROC TEMPLATE you can choose whether you want to pass the new style attributes on to descendants or not.

    To make a change in a child style definition that is passed in turn to the style elements that are defined in the parent, and that inherit from the style element that you redefine in the child style definition, then use the REPLACE statement. You can only use the REPLACE statement if you have specified a parent style definition. The following program changes the background color of celldataemphasis by using a REPLACE statement. You can think of this REPLACE statement as replacing the statement that defines the like-named style element in concepts.style1 . The REPLACE statement does not actually change the concepts.style1 , but PROC TEMPLATE builds concepts.style2 as if it had changed concepts.style1 .

    Example Code 9.15: Redefining a Style Element with the REPLACE Statement

    start example
     proc template;     define style concepts.style1;        style celldatasimple /           font_face=arial           background=very light vivid blue           foreground=white;        style celldataemphasis from celldatasimple /           foreground=blue           font_style=italic;        style celldatalarge from celldataemphasis /           font_weight=bold           font_size=5;     end;  run;  proc template:     define style concepts.style2;   parent=concepts.style1;       replace celldataemphasis from celldatasimple /   style celldatasmall from celldatalarge /           font_size=2;     end;  run; 
    end example
     

    This is how PROC TEMPLATE constructs concepts.style2 :

    1. The PARENT= attribute makes concepts.style1 the basis of the new style definition, concepts.style2 . concepts.style2 contains all the style elements that concepts.style1 contains: celldatasimple , celldataemphasis , and celldatalarge .

    2. concepts.style2 does nothing to celldatasimple . Therefore, in concepts.style2 , celldatasimple is the same as it is in concepts.style1 .

    3. The REPLACE statement essentially replaces the definition of celldataemphasis in concepts.style1 while concepts.style2 is being created. (It does not really alter concepts.style1 , but concepts.style2 is created as if it had.) Thus, not only does celldataemphasis now exist in concepts.style2 , but also every style element that concepts.style2 inherits from concepts.style1 is based on the replaced definition.

    A description of each style element in concepts.style2 follows :

    celldatasimple

    • is not redefined in concepts.style2 . Nor does it inherit from any other style element. Therefore, it has the same attributes as celldatasimple in concepts.style1 :

      • FONT_FACE=arial

      • BACKGROUND=very light vivid blue

      • FOREGROUND=white.

    celldataemphasis

    • is defined in concepts.style2 . It inherits from celldatasimple , so initially it has these attributes:

      • FONT_FACE=arial

      • BACKGROUND=very light vivid blue

      • FOREGROUND=white.

    • However, the REPLACE statement that creates celldataemphasis specifies a foreground color, a background color, and a font style. The foreground and background color specifications override the inherited attributes. Therefore, the final list of attributes for celldataemphasis is

      • FONT_FACE=arial

      • BACKGROUND=white

      • FOREGROUND=blue

      • FONT_STYLE=italic.

    celldatalarge

    • is not redefined in concepts.style2 . Therefore, concepts.style2 uses the same definition as concepts.style1 uses. The definition of celldatalarge is from celldataemphasis . Because celldataemphasis was created in concepts.style2 with a REPLACE statement, celldatalarge inherits the following attributes from the replaced definition of celldataemphasis :

      • FONT_FACE=arial (from concepts.style1 )

      • BACKGROUND=white (from concepts.style2 )

      • FOREGROUND=blue (from concepts.style2 )

      • FONT_STYLE=italic (from concepts.style2 ).

    • The definition of celldatalarge from concepts.style1 adds these attributes:

      • FONT_WEIGHT=bold (from concepts.style1 )

      • FONT_SIZE=5 (from concepts.style1 ).

    celldatasmall

    • exists only in concepts.style2 . It is created from celldatalarge . PROC TEMPLATE first looks for celldatalarge in concepts.style2 , but because it does not exist, it uses the definition in the parent style definition. Therefore, celldatasmall is just like celldatalarge except that the font size of 2 replaces the font size of 5. The final list of attributes for celldatasmall is

        • FONT_FACE=arial

        • BACKGROUND=while

        • FOREGROUND=blue

        • FONT_STYLE=italic

        • FONT_SIZE=2

    The following HTML output uses this new style definition, concepts.style2 :

    click to expand
    Display 9.11: Using the REPLACE Statement to Alter a Style Element and Its Children

Summary of Style Element Inheritance in a Style Definition with a Parent

The following points summarize style element inheritance in a style definition that has a parent:

  • You can create a new style element from any style element in the parent or the child style definition.

  • If you create a style element from another style element, then PROC TEMPLATE first looks in the current style definition for that element. If the style definition does not contain such an element, then PROC TEMPLATE looks in the parent (and in parent's parent, and so on).

  • A new style element inherits all the attributes from its parent.

  • You can specify additional attributes in the new style definition. The attributes are added to the attributes that the element inherits.

  • You can change the value of an inherited attribute by respecifying it in the definition of the new style element.

  • If you want to create a style element in the new style definition, then you must use the STYLE statement or the REPLACE statement

    • In the STYLE statement, you are creating a new style element. Only those style elements that explicitly inherit their attributes from the style element that you created inherit the changes. All other style elements inherit their attributes from the parent style definition.

    • In the REPLACE statement, you are replacing the like-named style element from the parent style definition in the new style definition. The REPLACE statement does not change the parent style definition. All style elements that inherit attributes from the style elements that inherit style elements that you created, inherit only the attributes that you specified in the REPLACE statement. All other attributes specified in the parent style definition are not used unless you specify them again in the style element that you created.




SAS 9.1 Output Delivery System. Users Guide
SAS 9.1 Output Delivery System Users Guide
ISBN: 1590472187
EAN: 2147483647
Year: 2004
Pages: 99
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net