Working with Styles

Changing the Style That Is Applied to ODS Graphs

Changing the Style in Your Program

When you use the ODS Graphics procedures or the Graph Template Language, you can easily change a graph's appearance by changing the style for an ODS destination. Changing the current style requires only the use of the STYLE= option in an ODS destination statement. The ODS destination statement is global and can be used anywhere in your SAS program. The statement remains in effect until you explicitly change it or start a new SAS session.
Note: The style that a destination uses is applied to tabular output as well as graphical output.
In the following example, the ODS destination statement specifies HTML as the destination and HTMLBlue as the style.
ods html style=htmlblue;
title "Model Height By Weight";
proc sgplot data=sashelp.class;
  reg x=height y=weight / clm cli;
run;
title;
HTML Output Using the HTMLBlue Style
HTML Output Using the HTMLBlue Style
The following displays show the output for the same graph when the STYLE= option is specified as Analysis and Journal, respectively.
HTML Output Using the Analysis Style
HTML Output Using the Analysis Style
HTML Output Using the Journal Style
HTML Output Using the Journal Style

Changing the Style in the ODS Graphics Designer or the ODS Graphics Editor

In the ODS Graphics Designer and the ODS Graphics Editor, you can use the menus to change the style for a particular graph.
  • In the ODS Graphics Designer, one way to change the style for a graph is to right-click the graph and select Graph Properties. In the Graph Properties dialog box, clicking the down arrow in the Style drop-down list displays the styles that are available.
    Styles in the Graph Properties Dialog Box (ODS Graphics Designer)
    Styles in the Graph Properties Dialog Box
    The default style for graphs created in the designer is Listing. You can change this default in the designer’s preferences.
  • The ODS Graphics Editor has a similar interface for changing the style of a graph. In the editor, you can change the style for a graph by selecting Formatthen selectStyle. Then select the style that you want.
    By default, ODS Graphics Editor files use the active ODS destination style that is specified in the SAS program.

Editing a Style

ODS styles are based on templates that define the specific visual attributes for your SAS output. You can use the following software to edit style templates:
  • TEMPLATE procedure
    You can modify the ODS style template for a style to make persistent changes to that style. Using the TEMPLATE procedure, you can modify the default SAS style templates as well as custom styles that have been created at your site.
    For more information about the TEMPLATE procedure, see SAS Output Delivery System: User's Guide.
  • ODS Graphics Designer
    The ODS Graphics Designer has an interactive graphical interface for designing and modifying custom styles. This interface, called the Graph Style Editor, makes it easy to design styles that you can apply to your SGD graphs. You can also use these custom styles for graphs that are generated outside of the designer.
Here is a high-level overview of the process using the ODS Graphics Designer
  1. In the designer, open the Graph Style Editor. Select Toolsthen selectStyle Editor.
  2. Create or modify a custom style. You cannot change the predefined SAS ODS styles. However, you can edit a SAS style, customize various style elements and attributes, and save your changes using a new style name.
    For complete instructions about creating custom styles, see Customizing Graph Styles in SAS ODS Graphics Designer: User's Guide.
  3. Apply the custom style to your ODS Graphics Designer graphs as appropriate.
  4. You can also use the style when you generate graphs outside of the ODS Graphics Designer. Follow these steps:
    1. To export the style, select Filethen selectExport Style and select the style (or styles) that you want to export.
    2. Run the exported code in SAS to compile a style and save it in the style template store.
    3. Do either or both of the following:
      • Apply the style to your procedures by specifying the style in the ODS destination statement.
      • Modify the style using the TEMPLATE procedure.

Changing the Appearance of Individual Graphics Elements in a Plot

Overview of Changing Graphics Elements

ODS Graphics software enables you to control the appearance of different parts of a graph without changing the overall style. For example, you can change the visual attributes of lines, bars, markers, text, and so on. These changes are limited to the current graph.
Each graphics element of a plot, such as a marker or a line, derives its visual attributes from a specific style element from the active style. Within a given style, the style elements give you more granular control of a graph's visual elements.
In general, there are two ways to change the appearance of a graphics element:
  • You can specify a different style element for the graphics element. For example, a density curve uses the default GraphFit style element for its visual attributes. You might instead specify the GraphFit2 style element.
  • You can change one or more attributes of a style element. For example, you might explicitly change the color of a density curve to red.
It is recommended that you specify style elements rather than explicit attributes whenever possible. The attributes of a style element are chosen to provide consistency and appropriate emphasis based on display principles for statistical graphics. When you specify a particular attribute, you override the style element. You might create a graph that is inconsistent with the style. If you later change the style for the graph, your override remains in effect and could clash with the new style.
Note: For bar charts, you also have the option to specify one of several bar skins. This option provides an easy way to enhance the appearance of the bars. The option is supported in the Graph Template Language, in the ODS Graphics procedures, and in the ODS Graphics Designer.
The following sections describe the options for changing the appearance of graphics elements in the ODS Graphics software.

Changing Graphics Elements in Your Program

The ODS Graphics software gives you the following options for changing the appearance of graphics elements in your program:
  • ODS Graphics procedures
    Many ODS Graphics procedure statements have options and suboptions that control the appearance of different parts of a graph. Typically, you can specify a style element, a hardcoded attribute value, or a combination of both. The following example specifies a style element for a density curve in a graph.
    proc sgplot data=sashelp.class noautolegend;
    density height / lineattrs=graphfit2;
    run;
    The following displays show the default and the modified appearance.
    Default Line Attributes
    GRAPHFIT2 Line Attributes
    Default Line Attributes
    GRAPHFIT2 Line Attributes
    The following example specifies a style element and a hardcoded attribute value. This example changes the line to a dash-dash-dot pattern (dash-dash-dot).
    density height / lineattrs=graphfit2 (pattern=dashdashdot);
  • Graph Template Language
    The Graph Template Language uses similar syntax to specify a style element, a hardcoded attribute value, or a combination of both. The following example specifies the marker color for a scatter plot.
    scatterplot x=XVAR y=YVAR / markerattrs=(color=red);
    This example was taken from Example of Creating a Template.

Changing Graphics Elements in ODS Graphics Designer

The ODS Graphics Designer gives you numerous options for changing the appearance of graphics elements in an SGD file. You can use the designer’s graphical interface to specify the style element or the element attributes (color, font size, and so on) of a graphics element.
For example, to change the properties of a graph title, right-click the title and select Title Properties from the pop-up menu. The following display shows the properties for a graph title.
GraphTitleText Style Element in the Text Properties Dialog Box
GraphTitleText Style Element in the Text Properties Dialog Box

Changing Graphics Elements in ODS Graphics Editor

The editor enables you to change the visual attributes of a graphics element, but not the style element. For example, to change the properties of a graph title, right-click the title and select Compose Rich Text from the pop-up menu. From the Compose Rich Text dialog box, you can change the text and the font properties. You can also use subscript or superscript values, and you can enter Unicode characters.
Compose Rich Text Dialog Box
Compose Rich Text Dialog Box