Hello,
It seems a very easy question but somehow I am struggling with this.
I just want to change the FONT (not font size, this I can do easily) of all text in a plot (in SGPLOT): axis labels and values, legend items...
I guess I have to define a new style, something like:
proc template;
define style my_style;
parent=styles.htmlblue;
class GraphValueText / font = ("<sans-serif>, <MTsans-serif>",20pt);
end;
How can I set the font to Times New Roman, or Arial, etc, instead of sans-serif?
Where can I find a list of available fonts?
And how do I apply the new style to the plot?
Could someone give an example (as easy as possible)?
Hello,
Below is an example of how to use different fonts. GraphLabelFont controls the axis labels and the legend label. GraphValueFont controls the axis tick values, and the values within the legend. Also, make sure that you actually look at the graph file that is being outputted, i.e. the .PNG file on your C drive.
proc template;
define style styles.new_font;
parent = styles.default;
class GraphFonts
"Fonts used in graph styles" /
'GraphValueFont' = ("Arial",9pt)
'GraphLabelFont' = ("Times New Roman Uni",10pt,
bold);
end;
run;
ods listing style = styles.new_font gpath = "C:\graph";
proc sgplot data=sashelp.class;
scatter x=height y=weight / group=sex;
run;
Hello,
Below is an example of how to use different fonts. GraphLabelFont controls the axis labels and the legend label. GraphValueFont controls the axis tick values, and the values within the legend. Also, make sure that you actually look at the graph file that is being outputted, i.e. the .PNG file on your C drive.
proc template;
define style styles.new_font;
parent = styles.default;
class GraphFonts
"Fonts used in graph styles" /
'GraphValueFont' = ("Arial",9pt)
'GraphLabelFont' = ("Times New Roman Uni",10pt,
bold);
end;
run;
ods listing style = styles.new_font gpath = "C:\graph";
proc sgplot data=sashelp.class;
scatter x=height y=weight / group=sex;
run;
Also, this link can show you how to find which fonts are available:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/graphref/n0840ghr9b9y3bn0zphem54hvgbt.htm
You're welcome. You can add the GraphBackground class to change the fill color from grey to white, as seen below.
proc template;
define style styles.new_font;
parent = styles.default;
class GraphBackground /
color = white;
class GraphFonts
"Fonts used in graph styles" /
'GraphValueFont' = ("Arial",9pt)
'GraphLabelFont' = ("Times New Roman Uni",10pt,
bold);
end;
run;
ods listing style = styles.new_font gpath = "C:\graph";
proc sgplot data=sashelp.class;
scatter x=height y=weight / group=sex;
run;
Another option would be to use the older SAS/Graph proc gplot, where you can control the text font with "goptions ftext=".
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.