I'm generating some plots from PROC UNIVARIATE, and I'm finding that I'm unable to contol the colors used, even though there are options to do so.
I'm trying code adapted from a short sample in the product documentation:
proc univariate;
histogram / normal(color=(orange black) mu=10 est sigma=0.5 est);
run;
...but I find the colors are not used as specified. I've checked both listing and HTML results. I'm using SAS 9.3 TS Level 1M1. I'm pretty new to SAS; is there something obvious that I'm missing.
Thanks, Andrew
PS: I find that I can control colors in other procedures such as PROC SGPLOT
Hi:
If you have ODS GRAPHICS turned OFF, then your COLOR choices will override what is specified in the STYLE template (as seen in #1 output below). However, if you have ODS GRAPHICS turned ON (as it is by default in SAS 9.3), then your COLOR choices in the syntax are ignored and ONLY the style template will impact your output (as shown in #2). I changed the colors to CYAN and RED, 2 colors which are not in the style template -- so their appearance would be immediately evident.
I prefer to explicitly take control of the ODS GRAPHICS statement so that I know exactly whether my syntax options are in control or whether the style template is in control. An additional option that can impact your output is whether you have the GSTYLE option turned on or off (OPTIONS NOGSTYLE). Consider the difference between #1a and #1b output...when you use the NOGSTYLE option, you are turning off the use of the ODS style template completely. By default, the state of this option is for GSTYLE to be turned ON.
Another option is to use PROC SGPLOT and the HISTOGRAM statement with an overlaid DENSITY statement to put the normal or kernel density curve on top of the histogram. The LINEATTRS option allows you to change the color of the density lines.
Or you could change the template, but there are a lot of other options available before you need to go down that road.
cynthia
ods listing close;
title; footnote;
ods graphics off;
options gstyle;
ods html path='c:\temp' (url=none)
file='ods_graf_off_gstyle_1a.html' style=sasweb;
proc univariate data=sashelp.class;
title '1a) Will Use Colors if ODS GRAPHICS is OFF';
var age;
histogram age/ normal(color=(cyan red) mu=10 est sigma=0.5 est);
run;
ods html close;
ods graphics off;
options nogstyle;
ods html path='c:\temp' (url=none)
file='use_ods_graf_off_nogstyle_1b.html' style=sasweb;
proc univariate data=sashelp.class;
title '1b) Will Use Diff Fill Colors if ODS GRAPHICS is OFF and NOGSTYLE option set';
var age;
histogram age/ normal(color=(cyan red) mu=10 est sigma=0.5 est);
run;
ods html close;
ods graphics on;
options gstyle;
ods html path='c:\temp' (url=none)
file='ods_graf_on_gstyle_2.html' style=sasweb;
proc univariate data=sashelp.class;
title '2) Will NOT Use Colors if ODS GRAPHICS and GSTYLE are ON';
var age;
histogram age/ normal(color=(cyan red) mu=10 est sigma=0.5 est);
run;
ods html close;
ods graphics on;
options gstyle;
ods html path='c:\temp' (url=none)
file='use_sgplot_histo_3.html' style=sasweb;
proc sgplot data=sashelp.class;
title '3) use SGPLOT ';
histogram age /fillattrs=(color=pink);
density age / lineattrs=(color=cyan) ;
density age / type=kernel lineattrs=(color=red);
run;
ods html close;
Graphs that come out of PROCS use ODS GRAPHICS and cannot be controlled using the standard graphic statements.
You'll need to modify the template that controls the graph if you're interested, see a paper here that explains it:
http://support.sas.com/resources/papers/proceedings09/323-2009.pdf
Or you can use the output from proc univariate and use an sgprocedure to get the graph you require.
Hi:
If you have ODS GRAPHICS turned OFF, then your COLOR choices will override what is specified in the STYLE template (as seen in #1 output below). However, if you have ODS GRAPHICS turned ON (as it is by default in SAS 9.3), then your COLOR choices in the syntax are ignored and ONLY the style template will impact your output (as shown in #2). I changed the colors to CYAN and RED, 2 colors which are not in the style template -- so their appearance would be immediately evident.
I prefer to explicitly take control of the ODS GRAPHICS statement so that I know exactly whether my syntax options are in control or whether the style template is in control. An additional option that can impact your output is whether you have the GSTYLE option turned on or off (OPTIONS NOGSTYLE). Consider the difference between #1a and #1b output...when you use the NOGSTYLE option, you are turning off the use of the ODS style template completely. By default, the state of this option is for GSTYLE to be turned ON.
Another option is to use PROC SGPLOT and the HISTOGRAM statement with an overlaid DENSITY statement to put the normal or kernel density curve on top of the histogram. The LINEATTRS option allows you to change the color of the density lines.
Or you could change the template, but there are a lot of other options available before you need to go down that road.
cynthia
ods listing close;
title; footnote;
ods graphics off;
options gstyle;
ods html path='c:\temp' (url=none)
file='ods_graf_off_gstyle_1a.html' style=sasweb;
proc univariate data=sashelp.class;
title '1a) Will Use Colors if ODS GRAPHICS is OFF';
var age;
histogram age/ normal(color=(cyan red) mu=10 est sigma=0.5 est);
run;
ods html close;
ods graphics off;
options nogstyle;
ods html path='c:\temp' (url=none)
file='use_ods_graf_off_nogstyle_1b.html' style=sasweb;
proc univariate data=sashelp.class;
title '1b) Will Use Diff Fill Colors if ODS GRAPHICS is OFF and NOGSTYLE option set';
var age;
histogram age/ normal(color=(cyan red) mu=10 est sigma=0.5 est);
run;
ods html close;
ods graphics on;
options gstyle;
ods html path='c:\temp' (url=none)
file='ods_graf_on_gstyle_2.html' style=sasweb;
proc univariate data=sashelp.class;
title '2) Will NOT Use Colors if ODS GRAPHICS and GSTYLE are ON';
var age;
histogram age/ normal(color=(cyan red) mu=10 est sigma=0.5 est);
run;
ods html close;
ods graphics on;
options gstyle;
ods html path='c:\temp' (url=none)
file='use_sgplot_histo_3.html' style=sasweb;
proc sgplot data=sashelp.class;
title '3) use SGPLOT ';
histogram age /fillattrs=(color=pink);
density age / lineattrs=(color=cyan) ;
density age / type=kernel lineattrs=(color=red);
run;
ods html close;
Thanks to both you and Reeza for the replies; everything is now working as I expect, and I'm glad to better understand the relationship between my SAS code, ODS graphics, and templates.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.