SAS ODS Style Option
There are many ways to alter how your SAS output looks. Whether you want to alter how your graphs, tables or other output looks, it is important to understand how SAS controls the visual characteristics of your output. First off, there are three layers that are vital to how your SAS output looks. Styles, Style Elements and Style Attributes.
- Styles determine the entire overall visual appearance of your output. A style is a collection of Style Elements, written in a PROC TEMPLATE syntax.
- Style Elements go a layer deeper than the style itself. A style element is a collection of Style Attributes and are each applicable to a specific part of your output. This means that each part of your output is associated with a Style Element. For example the markers in a Scatter Plot are associated with a style element, that controls shapes, colors and so on for different by groups in your data.
- Style Attributes are the most specific parts of the Style. Style Attributes are what makes up the Style Elements. If a style element specifies that the markers in a scatter plot to be shaped as red stars (ignoring groups), then the color red and the shape star are style attributes.
Obviously, the above explanation is very superficial. For a more thorough introduction to the three concepts, how they relate and how they are each written in the Template Procedure, see the SAS ODS Documentation Understanding Styles, Style Elements, and Style Attributes.
Changing Graph With ODS Style Option
/* HTMLBlue Style */ ods html style=HTMLBlue; title "Vbar Plot With ODS Style=HTMLBlue"; proc sgplot data=sashelp.iris; vbar species / response=SepalLength; run; title; /* Journal Style */ ods html style=Journal; title "Vbar Plot With ODS Style=Journal"; proc sgplot data=sashelp.iris; vbar species / response=SepalLength; run; title;
In the first SGPlot Procedure, I specify the HTMLBlue style. This is the default style for the HTML output destination. Next, I specify the Journal style for the same destination. Notice that several visual aspects change due to the change of style. The color of the bars change from blue to grey and the font seems different. In the next sections, we will see why these changes appear.
What Style Templates Are Available?
SAS provides a wide variety of predefined style templates. You have probably already used one or more of these without even knowing this, because every time SAS outputs to a destination, it implicitly uses the default template for that destination. You can run the code below to see what style templates are available in the Styles library.
proc template; list styles; run;
I encourage you to pick a few styles, insert them in an ODS STYLES= statement and run a procedure that creates an output. How does the output change with the associated style?
List Style Template In The Log
Above, you have seen examples of both the HTMLBlue and Journal style templates, and maybe a few more. But what do these actually look like? You can print a specific Style Template in the form of a Template Procedure to the log
proc template; source styles.htmlblue; run;
Above, you picked a few styles from the standard library and saw how these affected your output. Now, try to run the above code on the styles you picked. Can you make sense of the changes you observe in the visual appearance of your ouptut?
I admit, I rarely change the overall style of the output destination to make my output appear the way I want it. In my opinion, it does not offer much control over your output. And as a statistical programmer, one must aim for control. However, it is crucial if you truly want to understand why your output looks the way it does to understand the layers of Styles, Style Elements and Style Attributes explained at the top of the article. This article focuses on the relationship between these concepts and how to use the most superficial of these to modify your output. In future blog posts, I will explain how to use Style Elements and how to use Style Attributes to do the same.
If you are interested in learning about the basics of PROC TEMPLATE, check out Getting Started with the Graph Template Language in SAS, which I recommend and review in the blog post What SAS Books Are On My Shelf?.
Also, see the post Using the TMPLOUT= Option in SG Procedures.
You can download the entire code from this post here.