Chapter 1: Introduction to ODS Graphics

1.1  A Brief History of ODS Graphics

1.2  Automatic Graphs from SAS Analytical Procedures

1.3  Create Custom Graphs Using the Graph Template Language (GTL)

1.4  Create Custom Graphs Using the Statistical Graphics (SG) Procedures

1.5  Create Custom Graphs Using the ODS Graphics Designer Application

1.6  Data Sets and ODS Styles

1.7  Color and Grayscale Graphs

1.8  Summary

There has been a sea change in SAS graphics capabilities over the past few years. The advent of ODS Graphics has made it possible for many SAS analytical procedures to create graphs as part of the procedure output. This is of great convenience to users, as many standard graphs are created automatically, providing a consistency that was absent before. All users now get a set of graphs that are carefully designed by the procedure writers for each specific procedure.

These standard graphs are created by use of the Graph Template Language (GTL). GTL provides a flexible and structured syntax to define many types of graphs into StatGraph templates using the TEMPLATE procedure. These templates can range from the simplest scatter plot to complex diagnostics panels. These templates are then associated with data from within the analytical procedure to create the graphs. The same template can be used with different compatible data to create graphs for different use cases.

Other tools, such as the Statistical Graphics (SG) procedures and ODS Graphics Designer, are made available that provide an easy-to-use interface to the commonly used features of GTL. You can use GTL yourself to define your own graph template and render it using the SGRENDER procedure. Or, you can use the SG procedures or Designer to create your own custom graphs. Now you have a choice of different tools.

1.1 A Brief History of ODS Graphics

Prior to SAS 9.2, only a few analytical procedures created graphs automatically as part of the procedure output. The normal process for creating graphs from the procedure output often required post-processing of the data. First, it was necessary to run the procedure step to compute and save the data. Then, users had to use the SAS/GRAPH procedures to create custom plots from this data.

This process had some drawbacks.

•   There was no standard set of graphs that were available to all users of a procedure.

•   All users had to create their own graphs from the data.

•   Each user had to become proficient in SAS/GRAPH code, diverting precious resources away from the analysis task itself.

•   Important analysis data computed during the procedure step was lost once the procedure terminated.

In light of these issues, there was a strong desire that the analytical procedures create the appropriate graphical output automatically as part of the procedure step. However, visual presentation of the output from analytical procedures requires sophisticated graphs, as each procedure has its own unique requirements. To achieve this, it was necessary to develop a new structured graphics language that would allow for the definition of complex, sophisticated graphs in a systematic way. This led to the development of ODS Graphics software and the Graph Template Language.

The ODS Graphics software released with SAS 9.2 has made it easier for you to obtain high quality graphs with little or no effort in the following ways:

•   You can get automatic graphs from SAS analytical procedures.

•   You can create custom graphs using the Graph Template Language (GTL).

•   You can create custom graphs using the Statistical Graphics (SG) procedures.

•   You can create custom graphs using the ODS Graphics Designer application.

Let us review the benefits and audience for each of the above methods.

1.2 Automatic Graphs from SAS Analytical Procedures

Many Base SAS, SAS/STAT, SAS/QC, SAS/ETS, and SAS High-Performance Forecasting procedures create high quality graphs automatically. Below, we have enabled ODS Graphics software and then run the LIFETEST procedure.

ods graphics on;

proc lifetest data=BMT plots=survival(atrisk=0 to 2500 by 500);

   time T * Status(0);

   strata Group / test=logrank adjust=sidak;

   run;

Figure 1.2 – The Product-Limit Survival Estimates Graph1

image

To obtain automatic graphs, all you have to do is turn on ODS Graphics.

•   With SAS 9.3, ODS Graphics is on by default in DMS (windowing) mode, and the default output destination is HTML.

•   In SAS 9.2 for both line and DMS modes, ODS Graphics is off by default and graphics are not created automatically. The default open destination is LISTING. ODS Graphics can be turned on by using the following statement.
       ods graphics on / < options >;

Over 100 analytical procedures create statistical graphs as part of the analysis process. You do not need to know anything about ODS Graphics to have graphs created for you that are relevant to the analysis. The audience for such graphs is the analyst or statistician.

1.3 Create Custom Graphs Using the Graph Template Language (GTL)

GTL was originally designed to create complex graphs for the SAS analytical procedures. Just as with tabular data, there was a need to display the data in a graphical form for easier understanding by the user. With SAS 9.2, the Output Delivery System (ODS) was extended to support graphics in a way similar to tabular data. The TEMPLATE procedure was extended to create StatGraph templates. These templates are defined using the GTL syntax. SAS procedures use such predefined templates along with data generated during the procedure step to produce the graphs. These can vary from simple scatter plots to complex panels of fit diagnostics data.

You can use the TEMPLATE procedure and GTL to create the StatGraph templates for your own custom graphs. GTL provides you an extensive set of plot types, layouts, and other statements for legends, attribute maps, and so on, that you can use to define the graphs that you need.

Another important feature of ODS Graphics is the systematic usage of ODS styles for graphs. Each ODS destination has an associated default style, and all graphs and tables rendered to a destination use the attributes from the style to render themselves. The styles shipped with SAS are carefully designed to provide aesthetic output by default. You no longer have to tweak color and marker settings in the graphs to get great-looking graphs.

The GTL syntax is the foundation of ODS Graphics software and is used to define the structure of a graph. In this book, we will use GTL to create some of the more complex graphs. The audience for GTL is the advanced graph programmer.

1.4 Create Custom Graphs Using the Statistical Graphics (SG) Procedures

The SG procedures create commonly used graphs using a simple and concise procedure syntax. These procedures use GTL behind the scenes to create the graphs:

•   the SGPLOT procedure for single-cell graphs

•   the SGPANEL procedure for classification panel graphs

•   the SGSCATTER procedure for comparative scatter plots and matrices

In this book we will primarily use the SGPLOT procedure to create most of the commonly used clinical graphs and the SGPANEL procedure to create classification panels. The SG procedures would be the tool of choice for programmers comfortable with using procedure syntax for creating graphs. The audience for the SG procedures is the graph programmer.

1.5 Create Custom Graphs Using the ODS Graphics Designer Application

The easiest, pain-free, and fastest way to create a custom graph is by using the ODS Graphics Designer, referred to in this book as Designer. The interactive Designer application is the tool of choice for you if you fit the following profile:

•   You want to create a graph quickly using an interactive application.

•   You are not familiar with graph syntax, and have no desire to learn it.

•   You export your data to third-party software just to create graphs.

Designer can help you create graphs with zero programming. Here are some key features:

•   Designer is an interactive GUI application.

•   You can begin your graph from a gallery of commonly used graphs.

•   You can customize your graph by adding more plots and insets.

•   You can create single-call graphs, classification panels, and ad hoc layouts.

•   You can view the GTL code generated for you while creating the graph.

•   You can save your custom graphs to the graph gallery for quick access.

•   You can save your graph as a .sgd file to the file system.

•   You can run a Designer graph in batch using the SGDESIGN procedure and send the graph to the open ODS destinations with the same or different data.

Designer is not only a great interactive tool to create your graph, but it is also a great learning tool for GTL. You can see how the GTL is put together every time you make a change to the graph. You can copy the GTL code from the code window into the SAS program window and run the code. The audience for the ODS Graphics Designer is the data analyst or statistician. It can also be used by programmers for rapid prototyping or as a learning tool for GTL.

1.6 Data Sets and ODS Styles

Some of the examples in this book use the data sets available in the SASHELP library. These include CARS, HEART, and a few others. However, for creating clinical graphs we often need unique data sets that are not available in the SASHELP library. In this case, data is simulated using trigonometric and random number generator functions to create data appropriate for such graphs.

Custom styles are sometimes used to render the graphs in this book. Primarily, these are necessary to reduce the font sizes to help fit the graphs into the small space available. This is especially true for examples of multi-cell graphs.

1.7 Color and Grayscale Graphs

The graphs are created using the active style of the open destination. Often, these styles are optimized for full color output. This works well when the graph is also viewed in a color medium.

However, when color graphs are printed in grayscale, there is a significant loss of fidelity in the representation of distinct categories in the graph. For example, a graph with two series plots, one for Drug A and one for Drug B, can be well represented in color with use of two distinct colors such as red and blue. These colors are often designed to have equal weight to avoid unintentional bias.

When such a graph is printed in grayscale, these two series plots can look very similar unless they have other distinguishing features such as line patterns and marker shapes. Bar charts can benefit from use of fill patterns to facilitate discrimination between classifiers.

This book is printed in full color, so you can see the full impact of the graph. However, if you need to submit the graphs to a journal in grayscale, care should be taken to ensure that the different group classifications are easy to differentiate using marker symbols, line patterns, or fill patterns.

1.8 Summary

Starting with SAS 9.2, ODS Graphics software provides flexible ways to create graphs for multiple audiences.

•   As an analyst or a statistician, you can get statistical graphs automatically from the analytical procedures. These graphs are relevant to the analysis and do not require any extra effort on your part to create.

•   As an advanced graph programmer, you can use the GTL directly to create the complex graphs that you need. You can also create flexible graph templates that can be used with different data to create graphs.

•   As a graph programmer, you can use the Statistical Graphics procedures to create most of the commonly used graphs in most domains.

•   You can use the ODS Graphics Designer to quickly create graphs using a point-and-click method, without writing a single line of graph code. You can also use this tool to quickly prototype the graph you or your analyst might want, or you can generate graphs in bulk, based on the variables selected from a data set. You can also use Designer as a learning tool to learn GTL.

Starting with SAS 9.3, ODS Graphics is included with Base SAS. With SAS 9.3 and SAS 9.4, new features and plot types have been added to the software to make creating graphs truly easy. These tools enable you to layer multiple plot types in myriad ways to create the custom graph that you want. Annotation is supported starting with SAS 9.3, and can be used to add custom features that are otherwise hard to add using plot layers.

For clinical graphs, SAS 9.4 has introduced the new axis table statements. These statements make it a breeze to add axis aligned statistics to be displayed in any graph. All in all, you will find that one of the tools mentioned above will provide you the way to create the graph that you need.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset