BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marta25
Obsidian | Level 7

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)?

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

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;

 

 

View solution in original post

5 REPLIES 5
djrisks
Barite | Level 11

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;

 

 

djrisks
Barite | Level 11

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

marta25
Obsidian | Level 7
Thanks, this is nice, however now the background fill of the plot is grey. How do I change this to white/transparent?
djrisks
Barite | Level 11

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;
GraphGuy
Meteorite | Level 14

Another option would be to use the older SAS/Graph proc gplot, where you can control the text font with "goptions ftext=".

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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.

Discussion stats
  • 5 replies
  • 6210 views
  • 5 likes
  • 3 in conversation