Hello Everybody,
I'm using the code below but no matter what GOPTIONS I specify I get the same histogram. What I want to do is change the text font and fill colors in the histogram. What am I doing wrong?
ods html;
goptions reset=goptions;
ODS GRAPHICS on /RESET ;
goptions cback=blue htext=6 pct ftext="Cumberland AMT" FTITLE="Cumberland AMT";
title "Overlay Histograms with PROC SGPLOT";
proc sgplot data=Sashelp.Iris;
histogram PetalLength / binwidth=5 transparency=0.5
name="petal" legendlabel="Petal Width";
histogram SepalLength / binwidth=5 transparency=0.5
name="sepal" legendlabel="Sepal Width";
density PetalLength / type=kernel lineattrs=GraphData1; /* optional */
density SepalLength / type=kernel lineattrs=GraphData2; /* optional */
xaxis label="Length (mm)" min=0;
keylegend "petal" "sepal" / across=1 position=TopRight location=Inside;
run;
GOPTIONS do not work for SG Procedures.
Depending on what exactly you are trying to change you can usually change it in the SG procedures directly using the attribute options such as fillatrs or lineattrs.
There's several examples here that show how to specify colour and line types.
https://blogs.sas.com/content/graphicallyspeaking/2017/04/30/getting-started-with-sgplot-histograms/
histogram PetalLength / binwidth=5
transparency=0.5
name="petal"
legendlabel="Petal Width"
fillattrs=(color="CX8c6bb1");
GOPTIONS do not work for SG Procedures.
Depending on what exactly you are trying to change you can usually change it in the SG procedures directly using the attribute options such as fillatrs or lineattrs.
There's several examples here that show how to specify colour and line types.
https://blogs.sas.com/content/graphicallyspeaking/2017/04/30/getting-started-with-sgplot-histograms/
histogram PetalLength / binwidth=5
transparency=0.5
name="petal"
legendlabel="Petal Width"
fillattrs=(color="CX8c6bb1");
LIke @Reeza siad, look for procedure and plot options to do what you've done in the past in GOPTIONS. Another example is for CBACK, use this statement in SGPLOT:
styleattrs backcolor=blue;
The ODS GRAPHICS statement is also considered the "goptions" of ODS Graphics. Look there for more global options as well.
Hope this helps!
Dan
Through the ODS style, yes, but no through the proc syntax. You can do something like this:
proc template;
define style styles.narrow;
parent=styles.htmlblue;
class GraphFonts "Fonts used in graph styles" /
"GraphAnnoFont" = ("Arial Narrow, <MTsans-serif>", 10pt)
"GraphTitle1Font" = ("Arial Narrow, <MTsans-serif>", 14pt, bold)
"GraphTitleFont" = ("Arial Narrow, <MTsans-serif>", 11pt, bold)
"GraphFootnoteFont" = ("Arial Narrow, <MTsans-serif>", 10pt)
"GraphLabelFont" = ("Arial Narrow, <MTsans-serif>", 10pt)
"GraphLabel2Font" = ("Arial Narrow, <MTsans-serif>", 10pt)
"GraphValueFont" = ("Arial Narrow, <MTsans-serif>", 9pt)
"GraphUnicodeFont" = ("<MTsans-serif-unicode>", 9pt)
"GraphDataFont" = ("Arial Narrow, <MTsans-serif>", 7pt)
"NodeTitleFont" = ("Arial Narrow, <MTsans-serif>", 9pt)
"NodeLabelFont" = ("Arial Narrow, <MTsans-serif>", 9pt)
"NodeInputLabelFont" = ("Arial Narrow, <MTsans-serif>", 9pt)
"NodeDetailFont" = ("Arial Narrow, <MTsans-serif>", 7pt)
;
end;
run;
ods html style=narrow;
<your program>
ods html close;
This is a template that someone else posted a while back that's for Stephen Few style. I think he may have posted it on here somewere as well.
You can make the changes you want to set up your style and then yes, the style will modify the graphs automatically.
https://gist.github.com/statgeek/9845cc3d26e4c35e01a2
I did one up for our corporate colours because our design area was too slow to get the mods made up. Publications go through an approval process where I work.
It's possible, but the style elements you would need to change could depend on the plots you're using, as well as whether you are using GROUP or not. Style changes are best for persistent, "theme-level" changes, like your font change. If you are changing the colors to create a new theme, that would work well, but for "one off" changes, it is much better to change the colors directly on the plots. If the plots are using GROUP, you will either need to change the colors in the GraphData1-N style elements, or (if you have SAS 9.4) use the STYLEATTRS statement to override the style attributes in GaphData1-N (this is a much better choice for "one off" graph changes).
Hope this helps!
Dan
The default templates have GRAPHDATA1 through GRAPHDATA12 or GRAPHDATA15 (depending on style) which define default color, line style, marker symbol size.
one example from Styles.normal
style GraphData1 from Graph / linestyle = 1 contrastcolor = GraphColors('gcdata1') markersymbol = "CIRCLEFILLED" markersize = 10px color = GraphColors('gdata1') linethickness = 2px abstract = on;
the style has bunch of elements previous in the style that define color values for gdata1-12 (for graph color) gcdata1-1 (graph contrast color which are outlines) and several others. By using those color references you get consist usage in several places as typically the contrast will be a darker version of the graph color. Though if you want to drive people nuts I suppose you can define bar fill colors like dark green and outline with bright orange...
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!
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.