BookmarkSubscribeRSS Feed

How Do I Fix Common Problems in Output From ODS Graphics? Code, Q&A, Slides, and On-Demand Recording

Started ‎05-14-2021 by
Modified ‎08-19-2021 by
Views 3,818

Watch this Ask the Expert session to learn how to avoid common pitfalls when using ODS Graphics procedures. 

 

Watch the webinar

 

ODS Graphics.jpg

Join Marica Surratt as she discusses ODS graphics procedures and ways to improve the overall appearance of a graph by using attribute maps and adding special symbols. During this webinar you will learn:

  • How to get your desired colors and symbols in the graph output.
  • How to add special symbols in graph output
  • How to improve the overall look of your graph output.

The questions from the Q&A segment held at the end of the webinar are listed below along with the code that Marcia showed during her demo. The slides from the webinar are attached.

Q&A

Can I use my SAS/GRAPH statements, such as SYMBOL or PATTERN with the ODS Graphics Procedures?

No. The global SAS/GRAPH statements, such as SYMBOL or PATTERN, are ignored by the ODS Graphics Procedures. If you are converting existing SAS/GRAPH programs to use one of the ODS Graphics procedures, you will need to use statements or options with the ODS Graphics procedures for the same functionality as the SAS/GRAPH statements.

 

Are the ODS Graphics procedures the same as the SAS/GRAPH procedures?

The ODS Graphics procedures are not the same as the SAS/GRAPH procedures. The following documentation link provides information on specific differences: ODS Graphics and SAS/GRAPH

 

Do you have an ODS graphics cheat sheet you can recommend?

Here is an ODS Graphics Tip Sheet.

 

Where can we go to find a list of the options for all of the symbols and colors?

The direct link to the marker symbols in the documentation can be found at:

Marker Attributes and Symbols

The direct link for the color naming schemes in the documentation can be found at:

Color-Naming Schemes and a list of the predefined SAS named colors can be found at: Predefined Colors

You can also get to this information from the specific plot statement you are using. For example, in the documentation for SGPLOT or SGPANEL you can select the statement you want to learn more about. After you select the statement, SCATTER for example, you can click on MARKERATTRS to see all the attribute options for that statement. The SYMBOL= option will include the link to the symbols and the COLOR= option will include a link to the color naming schemes.

 

How do we look up the unicodes?

https://www.fileformat.info/info/unicode/ is one resource for the unicode hex values as well as fonts that support the character. For the reserved names that you can use with ODS Graphics in place of the unicode value, you can refer to the following documentation link: Reserved Keywords and Unicode Values

 

With SGPLOT available, is there any reason to write new SAS code using the original GPLOT procedure anymore?

Most of the functionality in PROC GPLOT is included in PROC SGPLOT. With new functionality being added to PROC SGPLOT, you will have more features/functionality when using SGPLOT.

 

To eliminate the borders around the bars, is there a way to do that without making the line color=fill color?

You can add the NOOUTLINE option on the VBAR statement in PROC SGPLOT to remove the bar outline. You can see this on the recording at 56:25.

 

I'm trying to save multiple ODS "tables" (actually, one table and one graphic) output from a single command.  I can't figure out how to specify separate locations and formats for them. ODS output for the Identify statement in Proc Arima includes the Autocorrelation Function graph, the Partial Autocorrelation Function graph, and a table of AC values (table names are AutoCorrGraph, PACFGRaph and ChiSqAuto, respectively". How do I save all three, specifying external locations and formats?

You can use the ODS OUTPUT statement to save each of the tables as specific data sets in different SAS data libraries. But, the graphs from the procedure would all be saved into the same location with the same output format if they are generated from the same procedure step.

 

What version of SAS do you need for these features / enhancements?

All the examples that were shown today were run using SAS 9.4M5. The ability to add special characters using a format is available beginning with SAS 9.4M3. The documentation section What's New in SAS ODS Graphics Procedures 9.4 describes the new features that were added to the ODS Graphics procedures in each maintenance release.

 

Could you clarify the difference between datacolors and datacontrastcolors?

DATACOLORS= is used for fill colors (bars with a fill). DATACONTRASTCOLORS= is used for the colors for marker symbols and line colors.

 

Is there a cross reference table that links the definitions like "markercolor" to the SG procedure syntax like "scatter"? I struggle to define those for different procedures in the attribute dataset.

The documentation link: Descriptions of the Reserved Variables shows which variables are used in the attribute map. The variables that begin with “FILL” will be applied to graph elements with a fill color, like band and bar charts. The variables that begin with “LINE” will be applied to graph elements that produce lines, such as SERIES or REG statement. The variables that begin with “MARKER” will be applied to marker symbols, such as a SCATTER statement or a SERIES statement with the MARKERS option.

 

Can we create a pop-up text label so when the mouse moves to the data point in the scatter plot, then it shows the student's name?

Adding the IMAGEMAP option on the ODS GRAPHICS statement when using ODS HTML will allow default data tips to be displayed. The TIP= option on the plot statement in PROC SGPLOT will allow you to specify variables for the tips, if supported. The documentation for the statement being used in PROC SGPLOT will include details for the TIP option. See recording at minute 59:40 for the demo.

 

Are we able to contact you directly if we have specific questions about tweaking graphs?

You can contact SAS Technical Support by phone, email, chat or a web form using the details in Contact SAS Technical Support and I or one of the other consultants who support ODS Graphics will be glad to help with your questions.

 

Any quick ways to add a table integrated in a vbar to display the count of the bar values [also for stacked vbar with 3%2B categories]?

You can use the XAXISTABLE or YAXISTABLE statement to add a table of values to your graph.

 

Are these methods fully visible, viable and the same in SAS Studio?

The ODS Graphics procedures will run and produce the same output in SAS Studio. You can find information on differences in the output format in SAS Studio in this link.

 

Can the underlying datasets be shared so we can test the code?

At the end of this document, I pasted the code for each of the topics that I discussed.

 

How frequently are the ODS Tip Sheets updated?

There is no schedule for when the ODS tip sheets are updated. Typically, updates are made when there are mistakes, new destinations are added, or an important feature is added.

 

Can you define font style only once and all titles and axis labels will follow it, so it's only defined once in one spot?

You can define a style using PROC TEMPLATE that defines the font for each of the style elements within the GraphFonts style element. The new style is included in the STYLE= option on the ODS statement for your ODS destination.

Documentation Style Elements for Use with ODS Graphics lists the style elements (look for the elements that include the Font as a recognized attribute) that are used with ODS Graphics and Modifying Style Templates describes how to modify a style template.

 

When you're trying to troubleshoot how to add a particular feature, what resources do you go to? {book, site, community solutions}

For adding a particular feature, you can look in Graph Samples Gallery, Graphically Speaking or the documentation to see if a sample has been written that produces the type of feature you want to have in your graph. The following books can also provide helpful information.  You can also check Graphics Programming - SAS Support Communities for others asking how to use the same functionality.

 

Any tips about special characters in GTL? Do the same basic tricks work there too?

The syntax for specifying the unicode values will be the same as we saw with PROC SGPLOT, using the correct GTL statement/option.

proc template;
  define statgraph plot;
    begingraph;
      EntryTitle "Title using Subscript 1 ^{unicode '2081'x}and superscript 2 ^{unicode '00b2'x}" / 
       textattrs=( family="Arial Unicode MS");
      layout overlay / xaxisopts=(Label="^{unicode pi}^{unicode mu}" 
                      LabelAttrs=(Family="Arial Unicode MS") 
                      TickValueAttrs=(Family="Arial Unicode MS"));
        ScatterPlot X=predict Y=height;
      endlayout;
    endgraph;
  end;
run;
proc sgrender data=sashelp.classfit template=plot;
  format predict myfmt.;
run;

 

How do you wrap long x- y- axis labels?

The SGPLOT procedure should automatically wrap long axis values to the next line. There is not an option in PROC SGPLOT to specify where the label will break. If you create your plot using GTL, you can specify the LABELSPLITCHAR= option with the character to use for the split character when using the LABELFITPOLICY=SPLIT option.

 

Is there a way to create a violin plot by using the SAS plot function?

The blog Violin Plots describes how to create violin plots using PROC SGPANEL.

 

How does Proc Template fit into ODS graphics?

The ODS Graphics procedures (SGPLOT, SGPANEL, as so on) internally generate Graph Template Language (GTL) code to produce the graph. You could use PROC TEMPLATE to define the GTL to create your graphs as an alternative to using one of the SG procedures. You can see some samples created using GTL in this link.

 

Can you color cluster lines a different color in dendrogram?

The Graph Template Language, GTL, does not currently provide the ability to display different colors in a dendrogram. The SGPLOT procedure does not include a DENDOGRAM statement.

 

I have several programs that are full of both old and new statements and I'm not really sure which one is overriding the other. I just know it works but would like to understand what is working and what I can get rid of. ODS is very powerful with many types of statements (e.g., graphics, listing, path) - does it matter where these are located and what options you can combine on the same statement?

In general, if you have multiple ODS statements using different destinations, those statements will not override each other. If you use an ODS GRAPHICS statement with the RESET option, any prior ODS Graphis options will be reset.  Any statements to open an ODS destination will need to come before any procedure whose output you want to include in the file. The ODS statement with the CLOSE option for the destination will close the file, so those statements need to be in that specific order. 

 

Example Code:

/* Specify a color for the bars in a bar chart
   by adding the FILLATTRS= option */
proc sgplot data=sashelp.class;
  vbar age / fillattrs=(color=lightgreen) group=sex;
run;
 
/* Specify the colors for the bars in a grouped
   bar chart by adding the DATACOLORS= option on
   the STYLEATTRS statement */
proc sgplot data=sashelp.class;
  styleattrs datacolors=(pink skyblue);
  vbar age / group=sex;
run;
 
 
/* Define an attribute map to associate bar colors
   with group variable values */
data attr;
  /* name the attribute map */
  id='colors';
  length fillcolor $7;
/* specify the VALUE of the group variable, if a format
   is associated with the variable, use the formatted value.
   Specify the FILLCOLOR for the bar for each group value. */
  input value $ fillcolor $;
  datalines;
F pink
M skyblue
;
run;
/* Reference the attribute map data set in the DATTRMAP=
   option on the PROC SGPLOT statement */ 
proc sgplot data=class dattrmap=attr;
  /* Reference the attribute map named colors in the 
     ATTRID= option */
  vbar age / group=sex attrid=colors;
run;
 
/* Modify the attribute map to include the SHOW variable 
   with a value of ATTRMAP so any group values listed in the
   attribute map will be included in the graph legend.
   Add the NOCASE variable with a value of TRUE to allow the 
   procedure to ignore case sensitivity of the group values */ 
data attr;
  id='colors';
  length fillcolor $7;
  input value $ fillcolor $;
  show='attrmap'; 
  nocase='true';
  datalines;
f pink
M skyblue
;
run;
proc sgplot data=class dattrmap=attr;
  vbar age / group=sex attrid=colors;
run;
 
/* Specify the colors for the marker symbols in a grouped
   scatter plot by adding the DATACONTRASTCOLORS= option on
   the STYLEATTRS statement */
proc sgplot data=sashelp.class;
   styleattrs datacontrastcolors=(pink skyblue);
   scatter x=age y=height / group=sex;
run;
 
/* Specify the symbols for the markers in a grouped
   scatter plot by adding the DATASYMBOLS= option on the 
   STYLEATTRS statement.
   The ATTRPRIORITY=NONE option on the ODS GRAPHICS statement
   prevents automatic cycling of the symbols through the colors
   if the ODS style being used has ATTRPRIORITY=COLOR defined */
ods graphics/ attrpriority=none;
proc sgplot data=sashelp.class;
   styleattrs datasymbols=(circlefilled squarefilled);
   scatter x=age y=height / group=sex;
run;
 
/* Define an attribute map to associate marker colors and symbols
   with group variable values */
data attr;
  /* name the attribute map */
  id='colors';
length markercolor $8 markersymbol $15;
/* specify the VALUE of the group variable, if a format
   is associated with the variable, use the formatted value.
   Specify the MARKERCOLOR for the color of the marker and the 
   MARKERSYBMOL for the symbol for each group value. */
  input value $ markercolor $ markersymbol $;
  datalines;
F pink squarefilled
M skyblue circlefilled
;
run;
/* Reference the attribute map data set in the DATTRMAP=
   option on the PROC SGPLOT statement */ 
proc sgplot data=sashelp.class dattrmap=attr;
  /* Reference the attribute map named colors in the 
     ATTRID= option */
   scatter x=age y=height / group=sex attrid=colors;
run;
 
/* Sort the plot data set by the X axis variable since
   line plots draw the line in data order */
proc sort data=sashelp.class out=class;
  by age;
run;
proc sgplot data=class;
   series x=age y=height / group=sex;
run;
 
 
/* Modify the attribute map to add the LINECOLOR for each
   of the grouped lines */
data attr;
  id='colors';
length markercolor $8 markersymbol linecolor $15;
  input value $ markercolor $ markersymbol $ linecolor $;
  datalines;
F pink squarefilled red
M skyblue circlefilled blue
;
run;
proc sort data=sashelp.class out=class;
  by age;
run;
proc sgplot data=class dattrmap=attr;
 /* Reference the attribute map named colors in the 
    ATTRID= option.
    Add the MARKERS option to include marker symbols*/
   series x=age y=height / group=sex attrid=colors markers;
run;
 
/* Overlay a scatter plot with a confidence band */
proc sgplot data=sashelp.classfit;
  scatter x=predict y=weight;
/* Add the TRANSPARENCY= option to allow the scatter markers
   to be seen through the band fill */
  band x=predict upper=upper lower=lower / transparency=0.2;
run;
 
 
/* Change the order of the SCATTER and BAND statements
   so the markers are drawn above the band */
proc sgplot data=sashelp.classfit;
  band x=predict upper=upper lower=lower;
  scatter x=predict y=weight;
run;
 
/* Add a title to the graph containing a subscript 1 and superscipt 2*/
/* Define an ODS escape character */
ods escapechar='^';
/* Specify the Arial Unicode MS font which supports the 
   subscript 1 unicode hex value 
   The syntax for the special charcters is the ods escape character 
   then within curly braces, the keyword UNICODE followed by the 4
   digit hex value of the symbol */
Title f="Arial Unicode MS" 
   "Title using Subscript 1 ^{unicode '2081'x}and superscript 2 ^{unicode '00b2'x}";
proc sgplot data=sashelp.classfit;
  band x=predict upper=upper lower=lower;
  scatter x=predict y=weight;
run;
 
/* Add an X axis label to contain the symbols for Greek letters pi and mu */
Title f="Arial Unicode MS" 
   "Title using Subscript 1 ^{unicode '2081'x}and superscript 2 ^{unicode '00b2'x}";
proc sgplot data=sashelp.classfit;
  band x=predict upper=upper lower=lower;
  scatter x=predict y=weight;
/* The syntax to include symbols in the axis label is the same as in 
   the title. But, since ODS Graphics defines reserved keywords for upper 
   and lower case Greek letters, only the reserved word is needed. */
xaxis label="^{unicode pi}^{unicode mu}";
run;
 
/* Add the greater than or equal to and less than or equal to 
   symbols to the X axis values using the VALUES= and VALUESDISPLAY=
   options when using a linear or discrete axis. */
Title f="Arial Unicode MS" 
   "Title using Subscript 1 ^{unicode '2081'x}and superscript 2 ^{unicode '00b2'x}";
proc sgplot data=sashelp.classfit;
  band x=predict upper=upper lower=lower;
  scatter x=predict y=weight;
xaxis label="^{unicode pi}^{unicode mu}"
   /* Specify the values for each tick mark */
     values=(60 80 100 120 140)
 /* Specify the text to be displayed at each tick mark. 
    The syntax to include the symbols is the same as we used 
    for the title and axis label */
     valuesdisplay=("^{unicode '2264'x} 60" "80" "100" "120" 
                 "^{unicode '2265'x}140");
run;
 
/* Define a format to display the greater than or equal to 
   and less than or equal to symbols.*/
proc format;
  value myfmt
   /* The syntax to include the symbol through a format is the 
        same, EXCEPT you cannot use the defined ODS escape character.
        The default ODS escape character (*ESC*) must be used instead. */
    low-60="(*ESC*){unicode '2264'x} 60"
140-high="(*ESC*){unicode '2265'x} 140"
    other=[3.];
run;
Title f="Arial Unicode MS" 
   "Title using Subscript 1 ^{unicode '2081'x}and superscript 2 ^{unicode '00b2'x}";
proc sgplot data=sashelp.classfit;
  band x=predict upper=upper lower=lower;
  scatter x=predict y=weight;
xaxis label="^{unicode pi}^{unicode mu}";
format predict myfmt.;
run;
/* Include a font for the axis label and tick values in cases where
   the unicode symbol is not supported by the default font */
proc sgplot data=sashelp.classfit;
  band x=predict upper=upper lower=lower;
  scatter x=predict y=weight;
xaxis label="^{unicode pi}^{unicode mu}"
        labelattrs=(family="Arial Unicode MS")
        valueattrs=(family="Arial Unicode MS");
format predict myfmt.;
run;

Recommended Resources

How to fix common problems in output from ODS graphics procedures

Documentation: SAS® 9.4 ODS Graphics: Procedures Guide, Sixth Edition

Making great graphs even better with ODS Graphics

Graphics Samples Output Gallery

Graphically Speaking blog

 

Want more tips? Be sure to subscribe to the Ask the Expert board to receive follow up Q&A, slides and recordings from other SAS Ask the Expert webinars.  

Version history
Last update:
‎08-19-2021 09:28 AM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Article Labels
Article Tags