Examples: Creating and Modifying Styles Using the TEMPLATE Procedure


Example 1: Creating a Stand-Alone Style Definition

PROC TEMPLATE features:

  • DEFINE STYLE statement

    • STYLE statement

      • BACKGROUND=

      • BORDERWIDTH=

      • CELLSPACING=

      • FONT_SIZE=

      • FONT_STYLE=

      • FONT_FACE=

      • FONT_WEIGHT=

      • FOREGROUND=

  • DEFINE TABLE statement

    • CLASSLEVELS= table attribute

    • DYNAMIC statement

    • MVAR statement

  • DEFINE COLUMN statement

    • BLANK_DUPS=

    • GENERIC=

    • STYLE=

    • HEADER=

  • 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 on page 97

Format: $CNTRY. on page 98

Program Description

This example creates a style definition that is not based on any other style definition. When you create a style definition, you will usually base it on one of the definitions that SAS provides (see Example 3 on page 355). However, this example is provided to show you some of the basic ways to create a style definition.

It is important to understand that by default, certain table elements are created with certain style elements. For example, unless you specify a different style element with the STYLE= attribute, ODS produces SAS titles with the systemtitle style element. Similarly, unless you specify otherwise , ODS produces headers with the header style element. (For information about each style element, see Appendix 4, 'HTML, Printer Family, and Markup Languages Style Elements and Their Inheritances,' on page 651.

Program

Create a new style definition newstyle with the style element cellcontents . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE STYLE statement creates a new style definition called newstyle . This STYLE statement defines the style element cellcontents . This style element is composed of the style attributes that appear on the STYLE statement. The FONT_FACE= attribute tells the browser to use the Arial font if it is available, and to look for the Helvetica font if Arial is not available.

 proc template;     define style newstyle;        style cellcontents /           background=blue           foreground=white           font_face="arial, helvetica"          font_weight=medium           font_style=roman           font_size=4; 

Create the style element header . This STYLE statement creates the style element header . By default, ODS uses header to produce both spanning headers and column headers. This style element uses different foreground and background colors from cellcontents . It uses the same font (Arial or Helvetica) and the same font style (roman) as cellcontents . However, it uses a bold font weight and a large font size .

 style header /    background=very light blue    foreground=blue    font_face="arial, helvetica"    font_weight=bold    font_style=roman    font_size=5; 

Create the style element systemtitle . This STYLE statement creates the style element systemtitle . By default, ODS uses systemtitle to produce SAS titles. This style element uses a color scheme of a red foreground on a white background. It uses the same font and font weight as header , but it adds an italic font style and uses a larger font size.

 style systemtitle /     background=white     foreground=red     font_face="arial, helvetica"     font_weight=bold     font_style=italic     font_size=6; 

Create the style element footer . This STYLE statement creates the style element footer . This style element inherits all the attributes of systemtitle . However, the font size that it inherits is overwritten by the FONT_SIZE= attribute in its definition.

 style footer from systemtitle /      font_size=3; 

Create the style element table . This STYLE statement creates the style element table . By default, ODS uses this style element to display tables.

 style table /      cellspacing=5      borderwidth=10; 

End the style definition. The END statement ends the style definition. The RUN statement executes the TEMPLATE procedure.

 end;  run; 

Create the table definition table1 . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE TABLE statement creates a new table definition called table1 .

 proc template;     define table table1; 

Specify the symbol that references one macro variable. The MVAR statement defines a symbol, sysdate9 , that references a macro variable. ODS will use the value of this macro variable as a string. References to the macro variable are resolved when ODS binds the table definition to the data component to produce an output object. SYSDATE9 is an automatic macro variable whose value is always available.

 mvar sysdate9; 

Specify the symbol that references a value to be supplied by the data component. The DYNAMIC statement defines a symbol, colhd , that references a value that the data component supplies when ODS binds the definition and the data component to produce an output object. The values for colhd are provided in the FILE statement in the DATA step that appears later in the program. Using dynamic column headers gives you more flexibility than does hard-coding the headers in the table definition.

 dynamic colhd; 

Control the repetition of values that do not change from one row to the next row. The CLASSLEVELS= attribute suppresses the display of the value in a column that is marked with BLANK_DUPS=ON if the value changes in a previous column that is also marked with BLANK_DUPS=ON. Because BLANK_DUPS= is set in a generic column, you should set this attribute as well.

 classlevels=on; 

Create the column char_var . This DEFINE statement and its attributes create the column definition char_var .

GENERIC= specifies that multiple variables can use the same column definition.

BLANK_DUPS= suppresses the display of the value in the column if it does not change from one row to the next (and, because CLASSLEVELS=ON for the table, if no values in preceding columns that are marked with BLANK_DUPS=ON changes).

HEADER= specifies that the header for the column will be the text of the dynamic variable COLHD, whose value will be set by the data component.

The STYLE= attribute specifies that the style element for this column definition is cellcontents .

The END statement ends the definition.

 define column char_var;     generic=on;     blank_dups=on;     header=colhd;     style=cellcontents;  end; 

Create the column definition num_var . This DEFINE statement and its attributes create the column definition num_var . GENERIC= specifies that multiple variables can use the same column definition. HEADER= specifies that the header for the column will be the text of the dynamic variable COLHD, whose value will be set by the data component.

The STYLE= attribute specifies that the style element for this column definition is cellcontents .

The END statement ends the definition.

 define column num_var;     generic=on;     header=colhd;     style=cellcontents;  end; 

Create the footer element table_footer . The DEFINE statement and its substatement define the table element table_footer . The FOOTER argument declares table_footer as a footer. The TEXT statement specifies the text of the footer. When ODS binds the data component to the table definition (in the DATA step that follows ), it will resolve the value of the macro variable SYSDATE9.

 define footer table_footer;     text 'Prepared on ' sysdate9;  end; 

End the table definition. This END statement ends the table definition. The RUN statement executes the PROC TEMPLATE step.

 end;  run; 

Stop the creation of the listing output. The ODS LISTING statement closes the Listing destination in order to conserve resources. The Listing destination is open by default.

 ods listing close; 

Create HTML output and specify the location for storing the HTML output. Specify the style definition that you want to use for the output. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the external file newstyle-body.htm in the current directory. The STYLE= option tells ODS to use newstyle as the style definition when it formats the output.

 ods html body='newstyle-body.htm'           style=newstyle; 

Specify the titles for the report. The TITLE statements provide two titles for the output.

 title 'Leading Grain Producers';  title2 'in 1996'; 

Create the data component. This DATA step does not create a data set. Instead, it creates a data component and, eventually, an output object.

The SET statement reads the data set GRAIN_PRODUCTION. The WHERE statement subsets the data set so that the output object contains information only for rice and corn production in 1996.

 data _null_;     set grain_production;     where type in ('Rice', 'Corn') and year=1996; 

Route the DATA step results to ODS and use the table1 table definition. The combination of the fileref PRINT and the ODS option in the FILE statement routes the results of the DATA step to ODS. (For more information about using the DATA step with ODS, see Chapter 3, 'Output Delivery System and the DATA Step,' on page 39.) The TEMPLATE= suboption tells ODS to use the table definition named table1 , which was previously created with PROC TEMPLATE.

 file print ods=(       template='table1' 

Specify the column definition to use for each variable. The COLUMNS= suboption places DATA step variables into columns that are defined in the table definition. For example, the first column-specification specifies that the first column of the output object contains the values of the variable COUNTRY and that it uses the column definition named char_var . GENERIC= must be set to ON in both the table definition and each column assignment in order for multiple variables to use the same column definition. The FORMAT= suboption specifies a format for the column. The DYNAMIC= suboption provides the value of the dynamic variable COLHD for the current column. Notice that for the first column the column header is Country , and for the second column, which uses the same column definition, the column header is Year .

 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'))     )  ); 

Write the data values to the data component. The _ODS_ option and the PUT statement write the data values for all columns to the data component. The RUN statement executes the DATA step.

 put _ods_;  run; 

Stop the creation of the HTML output and create the listing output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser. The ODS LISTING statement opens the Listing destination to return ODS to its default setup.

 ods html close;  ods listing; 
HTML Output: Specifying Colors and Fonts with User -Defined Attributes

You can use the 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 and the spacing between cells to confirm that the table itself is produced with the table style element.

click to expand
Display 9.12: HTML Output (Viewed with Microsoft Internet Explorer)

Example 2: Creating and Modifying a Style Definition with User-Defined Attributes

PROC TEMPLATE features:

  • DEFINE STYLE statement

    • STYLE statement with user-defined attributes

    • DEFINE TABLE statement

      • CLASSLEVELS= table attribute

      • DYNAMIC statement

      • MVAR statement

    • DEFINE COLUMN statement

      • BLANK_DUPS=

      • GENERIC=

      • HEADER=

      • STYLE=

  • DEFINE COLUMN statement

    • BLANK_DUPS= attribute

    • CELLSTYLE-AS statement

    • GENERIC= attribute

  • 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'' on page 97.

Format: $CNTRY. on page 98

Program 1: Description

This example creates a style definition that is equivalent to the style definition that Example 1 on page 342 creates. However, this style definition uses user-defined attributes to specify colors and fonts. This technique makes it possible to easily make changes in multiple places in your output.

Program 1: Creating the Style Definition

Create the style definition newstyle2 . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE STYLE statement creates a new style definition called newstyle2 . This STYLE statement defines the style element fonts .

This style element is composed of three user-defined attributes: cellfont , headingfont , and titlefont . Each of these attributes describes a font. This style definition specifies the font_face, font_size, font_weight, and the font_style for each of the three attributes. The font and font_width attributes are still defined by the default style definition.

 proc template;     define style newstyle2;        style fonts /           "cellfont"=("arial, helvetica", 4, medium roman)           "headingfont"=("arial, helvetica", 5, bold roman)           "titlefont"=("arial, helvetica", 6, bold italic); 

Create the style element colors . This STYLE statement defines the style element colors . This style element is composed of four user-defined attributes: light , medium , dark , and bright . Thevalues for medium and dark are RGB values equivalent to verylight blue and blue.

 style colors /        "light"=white        "medium"=cxaaaaff        "dark"=cx0000ff        "bright"=red; 

Create the three style elements: cellcontents , header , and systemtitle . Create the style element footer using inheritance. The style attributes are defined in terms of the user-defined attributes that were created earlier in the style definition. For example, the foreground color in cellcontents is set to colors("light") . Looking at the definition of colors , you can see that this is white. However, by setting the colors up in a style element with user-defined attributes, you can change the color of everything that uses a particular color by changing a single value in the style element colors .

 style cellcontents /     background=colors("dark")     foreground=colors("light")     font=fonts("cellfont");  style header /     background=colors("medium")     foreground=colors("dark")     font=fonts("headingfont");  style systemtitle /     background=colors("light")     foreground=colors("bright")     font=fonts("titlefont");  style footer from systemtitle /     font_size=3;  style table /     cellspacing=5     borderwidth=10; 

End the style definition. The END statement ends the style definition. The RUN statement executes PROC TEMPLATE.

 end;  run; 

Create the table definition table1 . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE TABLE statement creates a new table definition called table1 .

 proc template;     define table table1; 

Specify the symbol that references one macro variable. The MVAR statement defines a symbol, sysdate9 , that references a macro variable. ODS will use the value of this macro variable as a string. References to the macro variable are resolved when ODS binds the table definition to the data component to produce an output object. SYSDATE9 is an automatic macro variable whose value is always available.

 mvar sysdate9; 

Specify the symbol that references a value to be supplied by the data component. The DYNAMIC statement defines a symbol, colhd , that references a value that the data component supplies when ODS binds the definition and the data component to produce an output object. The values for colhd are provided in the FILE statement in the DATA step that appears later in the program. Using dynamic column headers gives you more flexibility than hard-coding the headers in the table definition does.

 dynamic colhd; 

Control the repetition of values that do not change from one row to the next row. The CLASSLEVELS= attribute suppresses the display of the value in a column that is marked with BLANK_DUPS=ON if the value changes in a previous column that is also marked with BLANK_DUPS=ON. Because BLANK_DUPS= is set in a generic column, you should set this attribute as well.

 classlevels=on; 

Create the column char_var . This DEFINE statement and its attributes create the column definition char_var .

GENERIC= specifies that multiple variables can use the same column definition.

BLANK_DUPS= suppresses the display of the value in the column if it does not change from one row to the next (and, because CLASSLEVELS=ON for the table, if no values in preceding columns that are marked with BLANK_DUPS=ON changes).

HEADER= specifies that the header for the column will be the text of the dynamic variable COLHD, whose value will be set by the data component.

The STYLE= attribute specifies that the style element for this column definition is cellcontents .

The END statement ends the definition.

 define column char_var;     generic=on;     blank_dups=on;     header=colhd;     style=cellcontents;  end; 

Create the column num_var . This DEFINE statement and its attributes create the column definition num_var . GENERIC= specifies that multiple variables can use the same column definition.

HEADER= specifies that the header for the column will be the text of the dynamic variable COLHD, whose value will be set by the data component.

The STYLE= attribute specifies that the style element for this column definition is cellcontents .

The END statement ends the definition.

 define column num_var;     generic=on;     header=colhd;     style=cellcontents;  end; 

Create the footer element table_footer . The DEFINE statement and its substatement define the table element table_footer . The FOOTER argument declares table_footer as a footer. The TEXT statement specifies the text of the footer. When ODS binds the data component to the table definition (in the DATA step that follows), it will resolve the value of the macro variable SYSDATE9.

 define footer table_footer;     text 'Prepared on ' sysdate9;  end; 

End the table definition. This END statement ends the table definition. The RUN statement executes the PROC TEMPLATE step.

 end;  run; 

Stop the creation of the listing output. The ODS LISTING statement closes the Listing destination to conserve resources. The Listing destination is open by default.

 ods listing close; 

Create the HTML output and specify the style definition that you want to use for the output. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the external file newstyle2-body.htm in the current directory. The STYLE= option tells ODS to use newstyle2 as the style definition when it formats the output.

 ods html body='newstyle2-body.htm'           style=newstyle2; 

Specify the titles for the report. The TITLE statements provide two titles for the output.

 title 'Leading Grain Producers';  title2 'in 1996'; 

Create the data component. This DATA step does not create a data set. Instead, it creates a data component and, eventually, an output object.

The SET statement reads the data set GRAIN_PRODUCTION. The WHERE statement subsets the data set so that the output object contains information only for rice and corn production in 1996.

 data _null_;     set grain_production;     where type in ('Rice', 'Corn') and year=1996; 

Route the DATA step results to ODS and use the table1 table definition. The combination of the fileref PRINT and the ODS option in the FILE statement routes the results of the DATA step to ODS. (For more information about using the DATA step with ODS, see Chapter 3, 'Output Delivery System and the DATA Step,' on page 39. The TEMPLATE= suboption tells ODS to use the table definition named table1 , which was previously created with PROC TEMPLATE.

 file print ods=(       template='table1' 

Specify the column definition to use for each variable. The COLUMNS= suboption places DATA step variables into columns that are defined in the table definition. For example, the first column-specification specifies that the first column of the output object contains the values of the variable COUNTRY and that it uses the column definition named char_var . GENERIC= must be set to ON in both the table definition and each column assignment in order for multiple variables to use the same column definition. The FORMAT= suboption specifies a format for the column. The DYNAMIC= suboption provides the value of the dynamic variable COLHD for the current column. Notice that for the first column the column header is Country , and for the second column, which uses the same column definition, the column header is Year .

 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'))     )  ); 

Write the data values to the data component. The _ODS_ option and the PUT statement write the data values for all columns to the data component. The RUN statement executes the DATA step.

 put _ods_;  run; 

Stop the creation of the HTML output and create the listing output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser. The ODS LISTING statement opens the Listing destination to return ODS to its default setup.

 ods html close;  ods listing; 
Original HTML Output

This HTML output is identical to 'HTML Output: Specifying Colors and Fonts with User-Defined Attributes' on page 347, which was produced with a style definition that used predefined style attributes. You can use the 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 and the spacing between cells to confirm that the table produced with the table style element.

click to expand
Display 9.13: HTML Output (Viewed with Microsoft Internet Explorer)
Program 2: Description

In the program Example 1 on page 342, if you want to change the color scheme so that the blues are replaced by pink and red, then you must change each occurrence of 'blue' and 'very light blue.' In this program, because colors are defined as user-defined attributes, you need to make the change only once.

Program 2: Changing User-Defined Attributes

To make the color scheme change, you need to change only the following section of code:

 style colors /        "light"=white        "medium"=cxaaaaff        "dark"=cx0000ff        "bright"=red; 

Change the attributes as follows:

 style colors /     "light"=white     "medium"=pink     "dark"=red     "bright"=red; 

Similarly, to change the font in any style element that uses cellfont , you can change the following section of code:

 "cellfont"=("arial, helvetica", 4, medium roman) 

Here is one example of how you can change the code:

 "cellfont"=("courier, arial, helvetica", 4, medium roman) 

The following HTML output shows the results of running the same program with these changes.

HTML Output: Changing Colors and Fonts of User-Defined Attributes

You can see that the font that is used in the cells is now Courier. This change occurs in multiple places even though you made only one change to the code for the font.

click to expand
Display 9.14: HTML Output with Changed Colors and Fonts (Viewed with Microsoft Internet Explorer)

Example 3: Modifying the Default Style Definition for the HTML and Markup Languages

PROC TEMPLATE features:

  • DEFINE STYLE statement

    • PARENT= attribute

    • REPLACE statement

    • style attributes

      • user-defined attributes

      • BACKGROUND=

      • BORDERWIDTH=

      • CELLPADDING =

      • CELLSPACING=

      • FONT=

      • FONT_STYLE=

      • FOREGROUND=

      • FRAME=

      • POSTHTML=

      • RULES=

Other ODS features:

  • ODS HTML statement

    • STYLE= option

  • ODS LISTING statement

  • ODS PATH statement

Data set: ENERGY'Program' on page 138

Formats: DIVFMT. and USETYPE. on page 139

Program 1: Description

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. This example shows you how to make changes to the default style definition for the HTML destination. The new style definition affects both the contents file and the body file in the HTML output. In the contents file, the modified style definition makes changes to the following:

  • the text of the header and the text that identifies the procedure that produced the output

  • the colors for some parts of the text

  • the font size of some parts of the text

  • the spacing in the list of entries in the table of contents.

In the body file, the modified style definition makes changes to the following:

  • two of the colors in the color list. One of these colors is used as the foreground color for the table of contents, the byline, and column headers. The other is used for the foreground of many parts of the body file, including SAS titles and footnotes.

  • the font size for titles and footnotes

  • the font style for headers

  • the presentation of the data in the table by changing attributes such as cellspacing, rules, and border width.

Note: Remember that when a STYLE statement creates a style element in the new style definition, only style elements that explicitly inherit from that style element in the new definition will inherit the change. When a REPLACE statement creates a style element in the new style definition, all style elements that inherit from that element inherit the definition that is in the new style definition, so the change appears in all children of the element.

Program 1: Using the Default Style Definition with PROC PRINT

Specify the search path in order to locate the table definition. This statement specifies which locations to search for definitions that were created by PROC TEMPLATE, as well as the order in which to search for them. The statement is included to ensure that the example works correctly. However, if you have not changed the path, then you do not need to include this statement because it specifies the default path.

 ods path sasuser.templat(update) sashelp.tmplmst(read); 

Stop the creation of the listing output. The ODS LISTING statement closes the Listing destination to conserve resources. The Listing destination is open by default.

 ods listing close; 

Create the HTML output and specify the name of the HTML file. Specify the style definition that you want to use for the output. The ODS HTML statement opens the HTML destination and creates HTML output. The output from PROC PRINT is sent to the body file. FRAME= and CONTENTS= create a frame that includes a table of contents that links to the contents of the body file. The body file also appears in the frame.

The STYLE= option tells ODS to use styles.default as the style definition when it formats the output. Strictly speaking, this option is unnecessary because it specifies the default style definition, but it is included for clarity.

 ods html body='sasdefaultstyle-body.htm'           contents='sasdefaultstyle-content.htm'           frame='sasdefaultstyle-frame.htm'           style=styles.default; 

Specify the titles and footnote for the report. The TITLE and FOOTNOTE statements provide two titles and a footnote for the output. The FOOTNOTE statement uses double rather than single quotes so that the macro variable resolves.

 title 'Energy Expenditures for Each Region';  title2 '(millions of dollars)';  footnote "Report prepared on &sysdate9"; 

Print the report. PROC PRINT creates a report that includes three variables. ODS writes the report to the BODY file.

 proc print data=energy noobs;     var state type expenditures;     format division divfmt. type usetype. expenditures comma12.;     by division;     where division=2 or division=3;  run; 
Program 2: Modifying the Default Style Definition and Using It with PROC PRINT

Create the style definition customdefault . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE STYLE statement creates a new style definition called customdefault .

 proc template;     define style customdefault; 

Specify the parent style definition from which the customdefault style definition inherits its attributes. The PARENT= attribute specifies styles.default as the style definition from which the current style definition inherits. All the style elements, attributes, and statements that are specified in the parent's definition are used in the current definition unless the current definition overrides them.

 parent=styles.default; 

Change the attributes of the style element color_list . This REPLACE statement adds to the child style definition the style element color_list , which also exists in the parent style definition. You can think of the REPLACE statement as replacing the definition of color_list in the parent style definition. The REPLACE statement does not actually change the parent style definition, but PROC TEMPLATE builds the child style definition as if it had changed the parent. All style elements that use the user-defined attributes that color_list defines ( fgB2 , fgB1 , etc.) use the attributes that are specified in the REPLACE statement, not the ones that are specified in styles.default . Therefore, if you change a color here, then you change every occurrence of the color in the HTML output. This REPLACE statement changes the values of fgA2 and fgA from a greenish blue to a pure blue and from a slightly darker greenish blue to a purple. (The first two digits of the hex value represent red, the next two represent green, and the last two represent blue.)

 replace color_list /     'fgB2' = cx0066AA     'fgB1' = cx004488     'fgA4' = cxAAFFAA     'bgA4' = cx880000     'bgA3' = cxD3D3D3  /* changed from cx0033AA */     'fgA2' = cx0000FF     'bgA2' = cxB0B0B0     'fgA1' = cx000000     'bgA1' = cxF0F0F0  /* changed from cx002288 */     'fgA' = cx660099     'bgA' = cxE0E0E0; 

Change the attributes of the style element titlesandfooters . This REPLACE statement adds to the child style definition the style element titlesandfooters , which also exists in the parent style definition. The new definition does not inherit attributes from any style element, but it will pass its attributes to any style element that inherits from titlesandfooters or from a child of titlesandfooters . This style element uses systitlefg and systitlebg for colors, but it changes the font size from the relative size of 4 that is specified in titlefont2 to a relative size of 3. As a result, the titles and footnotes in Display 9.16 on page 361 are smaller than the ones in Display 9.15 on page 357.

click to expand
Display 9.15: HTML Output from PROC PRINT Using the Default Style Definition
click to expand
Display 9.16: HTML Output from PROC PRINT with the Customized Style Definition
 replace titlesandfooters /     foreground=colors("systitlefg")     background=colors("systitlebg")     font=fonts("titlefont2") font_size=3; 

Change the attributes of the style element byline . Specify that the style element byline inherits its attributes from the titlesandfooters style element. This REPLACE statement adds to the child style definition the style element byline , which also exists in the parent style definition. This style element inherits all attributes from titlesandfooters as it is specified in the previous REPLACE statement. Therefore, the initial definition for the byline includes the foreground and background colors that are used for system titles, and a smaller version of titlefont2 . However, the FOREGROUND= attribute replaces the foreground color with the foreground color that is used for headers. Note that in the default style definition, the background color for the byline differs from the background color for the document, so it appears as a gray stripe in Display 9.15 on page 357. In this customized style definition, the stripe disappears because the background color for the byline and the document are the same.

 replace byline from titlesandfooters /     foreground=colors("headerfg"); 

Change one attribute in the style definition header . This STYLE statement adds the italic font style to the attributes that header inherits from the header style element that is defined in the parent style definition. The change does not affect headerfixed and the other style elements that inherit from header in the parent style definition.

 style header from header /     font_style=italic; 

Customize the text that is used in parts of the output. This REPLACE statement alters the text that is used in parts of the HTML output. In the contents file, the default style definition uses 'The' as the value of prefix1 and 'Procedure' as the value of suffix1 . Thus, in HTML output that uses the default style definition, the output from PROC PRINT is identified by '1. The PRINT Procedure' (see Display 9.15 on page 357). In the customized style definition, the text that identifies the output reads '1. PROC PRINT'. The heading that appears at the top of the contents file has been changed from 'Table of Contents' to 'Contents', and the heading at the top of the table of pages has been changed from 'Table of Pages' to 'Pages'. The banners have been changed to use mixed case. (Note that neither these banners nor the table of pages is visible in the HTML output from this example, but the attributes are included so that you can use the style definition in a variety of circumstances.)

 replace text /     "prefix1" = "PROC "     "suffix1" = ":"     "Content Title" = "Contents"     "Pages Title" = "Pages"     "Note Banner" = "Note:"     "Warn Banner" = "Warning:"     "Error Banner" = "Error:"     "Fatal Banner" = "Fatal:"     ; 

Customize the presentation of the HTML table that contains the output from PROC PRINT. This STYLE statement changes the presentation of the HTML table that contains the output from PROC PRINT. The background color, the kind of box that surrounds the table, and the cell padding remain the same as in styles.default , but all the other attributes are changed. RULES=COLS draws rules only between the columns of the table. CELLSPACING=0 removes the spacing between the cells of the table so that the data appear on a continuous background. BORDERWIDTH= increases the width of the table's border. The changes dramatically alter the appearance of the HTML output.

 style table from table /     rules=cols     cellspacing=0     borderwidth=5; 

Change the color of links and the foreground. This STYLE statement changes the value of the VISITEDLINKCOLOR= attribute in the style element contents so that the links in the table of contents appear in the same color as the rest of the table of contents. It also changes the foreground color so that the title of the table of contents appears in the same color as system titles.

 style contents from contents /     visitedlinkcolor=colors("systitlefg")     foreground = colors('systitlefg'); 

Add more space between the items in the table of contents. This STYLE statement adds the POSTHTML= attribute so that the items in the table of contents are displayed with extra space between them.

 style contentitem from contentitem /     posthtml='<p>'; 

Stop the creation of the customized style definition. The END statement ends the style definition. The RUN statement executes the PROC TEMPLATE step.

 end;  run; 

Create the HTML output and specify the specify the style definition that you want to use for the output. The ODS HTML statement opens the HTML destination and creates HTML output. The output from PROC PRINT is sent to the body file. FRAME= and CONTENTS= create a frame that includes a table of contents that links to the contents of the body file. The body file also appears in the frame.

The STYLE= option tells ODS to use customdefault as the style definition when it formats the output.

 ods html body='customdefaultstyle-body.htm'           contents='customdefaultstyle-content.htm'           frame='customdefaultstyle-frame.htm'           style=customdefault; 

Specify the titles and footnote for the report. The TITLE and FOOTNOTE statements provide two titles and a footnote for the output. The FOOTNOTE statement uses double rather than single quotes so that the macro variable resolves.

 title 'Energy Expenditures for Each Region';  title2 '(millions of dollars)';  footnote "Report prepared on &sysdate9"; 

Print the customized report. PROC PRINT creates a report that includes three variables. ODS writes the report to the body file. This PROC PRINT step is the same one that was used with the default style definition earlier.

 proc print data=energy noobs;     var state type expenditures;     format division divfmt. type usetype. expenditures comma12.;     by division;     where division=2 or division=3;  run; 

Stop the creation of the HTML output and initiate the creation of listing output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser. The ODS LISTING statement opens the Listing destination to return ODS to its default setup.

 ods html close;  ods listing; 

Example 4: Defining a Table and Graph Style

PROC TEMPLATE features:

  • DEFINE STYLE statement

    • PARENT= attribute

    • REPLACE statement

    • style attributes

    • user defined attributes

    • BACKGROUND=

    • BORDERCOLORDARK=

    • BORDERCOLORLIGHT=

    • BORDERWIDTH=

    • CELLPADDING=

    • CELLSPACING=

    • DROPSHADOW =

    • ENDCOLOR=

    • FONT=

    • FOREGROUND=

    • FRAME=

    • GRADIENT_DIRECTION=

    • IMAGE=

    • JUST=

    • OUTPUTWIDTH=

    • RULES=

    • TRANSPARENCY=

    • VJUST=

  • style elements

    • GraphAxisLines

    • GraphBackground

    • GraphBorderLines

    • GraphCharts

    • GraphLabelText

    • GraphWalls

Program Description

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. This example shows you how the SAS defined graph style, Science , was created.

Note: Remember that when a STYLE statement creates a style element in the new style definition, only style elements that explicitly inherit from that style element in the new definition inherit the change. When a REPLACE statement creates a style element in the new style definition, all style elements that inherit from that element inherit the definition that is in the new style definition, so the change appears in all children of the element.

Program

Create the style definition Science . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE STYLE statement creates a new style definition in the STYLES catalog called Science .

 proc template;       define style Styles.Science; 

Specify the parent style definition from where the SCIENCE style definitions inherits its attributes. The PARENT= attribute specifies STYLES.DEFAULT as the style definition that the current style definition inherits from. All the style elements and attributes and statements that are specified in the parent's definition are used in the current definition unless the current definition overrides them.

 parent = styles.default; 

Change the attributes fonts in the parent style definition by replacing it in the child style definition Science . The REPLACE statement adds to the child style definitions the style elements fonts, which also exist in the parent style definitions. While the REPLACE statement does not actually change the parent definition, PROC TEMPLATE builds the child style definition as if it had changed the parent. All style elements that use the user-defined attributes that fonts define use the attributes that are specified in the REPLACE statements, not the ones that are specified in the STYLES.DEFAULT style definition.

 replace fonts /     'TitleFont2' = ("Verdana, Verdana, Helvetica, sans-serif",14pt,Bold)     'TitleFont' = ("Verdana, Verdana, Helvetica, sans-serif",18pt,Bold)     'StrongFont' = ("Verdana, Verdana, Helvetica, sans-serif",14pt,Bold)     'EmphasisFont' = ("Verdana, Verdana, Helvetica, sans-serif",10pt,     Italic)     'FixedEmphasisFont' = ("'Courier New', Courier, monospace",10pt,     Italic)     'FixedStrongFont' = ("'Courier New', Courier, monospace",10pt,Bold)     'FixedHeadingFont' = ("'Courier New', Courier, monospace",10pt)     'BatchFixedFont' = ("'Courier New', Courier, monospace",10pt)     'FixedFont' = ("'Courier New', Courier, monospace",10pt)     'headingEmphasisFont' = ("Verdana, Verdana, Helvetica, sans-serif",14     pt,Bold Italic)     'headingFont' = ("Verdana, Verdana, Helvetica, sans-serif",14pt,Bold)     'docFont' = ("Verdana, Verdana, Helvetica, sans-serif",8pt,Bold); 

Change the attributes for graph style specific fonts. The REPLACE statement adds to the child style definitions the style elements GraphFonts , which also exist in the parent style definitions. While the REPLACE statement does not actually change the parent definition, PROC TEMPLATE builds the child style definition as if it had changed the parent. All the style elements that use the user-defined attributes that GraphFonts define use the attributes specified in the REPLACE statement, not those specified in STYLES.DEFAULT style definition.

 replace GraphFonts /           'GraphValueFont' = ("Verdana",10pt)           'GraphLabelFont' = ("Verdana",14pt,Bold); 

Change the attributes colors in the parent style definition by replacing it in the child style definition Science . The REPLACE statement adds to the child style definitions the style elements colors , which also exist in the parent style definitions. While the REPLACE statement does not actually change the parent definition, PROC TEMPLATE builds the child style definition as if it had changed the parent. All style elements that use the user-defined attributes that colors define use the attributes that are specified in the REPLACE statements, not the ones that are specified in STYLES.DEFAULT style definition.

 replace colors /      'headerfgemph' = cx31035E      'headerbgemph' = cxFFFFFF      'headerfgstrong' = cx31035E      'headerbgstrong' = cxFFFFFF      'headerfg' = cx31035E      'headerbg' = cxFFFFFF      'datafgemph' = cx31035E      'databgemph' = cxDFECE1      'datafgstrong' = cx31035E      'databgstrong' = cxDFECE1      'datafg' = cx31035E      'databg' = cxDFECE1      'batchfg' = cx31035E      'batchbg' = cxDFECE1      'tablebg' = cx31035E      'tableborderdark' = cx909090      'tableborderlight' = cxFFFFFF      'tableborder' = cxFFFFFF      'notefg' = cx31035E      'notebg' = cxDFECE1      'bylinefg' = cx31035E      'bylinebg' = cxDFECE1      'captionfg' = cx31035E      'captionbg' = cxDFECE1      'proctitlefg' = cx31035E      'proctitlebg' = cxDFECE1      'titlefg' = cx31035E      'titlebg' = cxDFECE1      'systitlefg' = cx31035E      'systitlebg' = cxDFECE1      'Conentryfg' = cx31035E      'Confolderfg' = cx31035E      'Contitlefg' = cx31035E      'link2' = cx800080      'link1' = cx0000FF      'contentfg' = cx31035E      'contentbg' = cxDFECE1      'docfg' = cx31035E      'docbg' = cxDFECE1; 

Change the attributes for graph style specific colors. The REPLACE statement adds to the child style definitions the style elements GraphColors , which also exist in the parent style definitions. While the REPLACE statement does not actually change the parent definition, PROC TEMPLATE builds the child style definition as if it had changed the parent. All the style elements that use the user-defined attributes that GraphColors define use the attributes that are specified in the REPLACE statement, not the attributes that are specified in STYLES.DEFAULT.

 replace GraphColors /           'gconramp3cend' = cxDD6060           'gconramp3cneutral' = cxFFFFFF           'gconramp3cstart' = cx6497EB           'gramp3cend' = cxBED8D3           'gramp3cneutral' = cxFFFFFF           'gramp3cstart' = cxAAB6DF           'gconramp2cend' = cx6497EB           'gconramp2cstart' = cxFFFFFF           'gramp2cend' = cx548287           'gramp2cstart' = cxFFFFFF           'gtext' = CX31035E           'glabel' = CX31035E           'gborderlines' = CX31035E           'goutlines' = CX31035E           'ggrid' = CX31035E           'gaxis' = CX31035E           'gshadow' = CX707671           'glegend' = CXFFFFFF           'gfloor' = CXDFECE1           'gwalls' = CXFFFFFF           'gcdata12' = cxFF667F           'gcdata11' = cx5050CC           'gcdata10' = cxE100BF           'gcdata9' = cx007F00           'gcdata8' = cxB99600           'gcdata7' = cx7F7F7F           'gcdata6' = cx984EA3           'gcdata5' = cx4DAF4A           'gcdata4' = cxA65628           'gcdata3' = cxFF7F00           'gcdata2' = cx377DB8           'gcdata1' = cxE31A1C           'gdata12' = CX4A5573           'gdata11' = CXCFB1E2           'gdata10' = CX8E829D           'gdata9' = CX2952B1           'gdata8' = CXAAB6DF           'gdata7' = CX6771C2           'gdata6' = CXBED8D3           'gdata5' = CX8B65A3           'gdata4' = CXBCD3AB           'gdata3' = CX548287           'gdata2' = CX7DC1C9           'gdata1' = CX9580D5; 

Specify attributes for the table. This STYLE statement is applied to tables. This statement specifies a cell padding of 5 and a cell spacing of 2 , that the BORDERCOLORDARK, TABLEBORDERCOLORDARK , which is cx909090, and that the BORDERCOLORLIGHT, TABLEBORDERLIGHT , which is cxFFFFFF, should blend to create the table border color, and sets a BORDERWIDTH of 2 . Although these specific attributes are set with this STYLE statement, all other table attributes are inherited from the style elements that are defined in the parent style definitions.

 style Table from Output /      cellpadding = 5      cellspacing = 2      bordercolordark = colors('tableborderdark')      bordercolorlight = colors('tableborderlight')      borderwidth = 2; 

Specify attributes for the GraphLabelText element. This STYLE statement is applied to the graph's label text. A DROPSHADOW attribute is applied.

 style GraphLabelText from GraphLabelText      "Label attributes" /      dropshadow = on; 

Replace the background for the Graph. This STYLE statement is applied to the graph's background. DOCBG is specified as the background colors, with SCIENCE.GIF justified to the left and bottom as the background image.

 replace GraphBackground     "Graph background attributes" /     background = colors('docbg')     image = "//dntsrc/sas/m900/ods/misc/Science.gif"     just = L     vjust = B; 

Specify attributes for the GraphAxisLines element. This STYLE statement is applied to the graph's axis line. The OUTPUTWIDTH is 2 .

 style GraphAxisLines from GraphAxisLines      "Axis line attributes" /      outputwidth = 2; 

Specify attributes for the GraphBorderLines element. This STYLE statement is applied to the borderlines in the graph. The OUTPUTWIDTH is 2 and the FOREGROUND color defined in gaxis , which is CX31035E, is used.

 style GraphBorderLines from GraphBorderLines      "Border attributes" /      outputwidth = 2      foreground = colors('gaxis'); 

Specify attributes for the GraphCharts element. This STYLE statement is applied to the graph's chart. The data elements of the graph have a TRANSPARENCY of 25 percent.

 style GraphCharts from GraphCharts      "Chart Attributes" /      transparency = 0.25; 

Specify attributes for the GraphWalls element. This STYLE statement is applied to the walls inside of the graph's axes. The GRADIENT_DIRECTION is set to Xaxis , meaning the gradient is going left to right. The ENDCOLOR, defined in gwalls , which is CXFFFFFF, is the final color used with the gradient. The data elements of the graph have a TRANSPARENCY of 100 percent. Since a STARTCOLOR is not specified, the beginning of the gradient is completely transparent.

 style GraphWalls from GraphWalls      "Wall Attributes" /      gradient_direction = "Xaxis"      endcolor = colors('gwalls')      transparency = 1.0 

Add the style to the specified catalog. The END statement ends the style definition. The RUN statement executes the PROC TEMPLATE step.

 end;  run; 



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