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

 

When creating charts in proc sgplot (for example see histogram code below) the title is always positioned outside of the chart area, so that when copying and pasting the chart into an email the title and chart are two separate items. 

 

proc sgplot data=tme_a_data;
	title "Cost distribution for TME category='A'";
	vbarparm category=sum_category response=sum_proportion;
	xaxis tickvalueformat=dollar7. label="Cost";
	yaxis tickvalueformat=percent5. grid label="Percentage" values=(0 to .30 by .05);
run;

 

 

Is it possible to locate the title *inside* of the chart area "box", just above the plot (but not inside the axes)? I'd like title and chart to be a single picture.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

There is a much easier way!  Use the GTITLE option on the ODS statement.  If allowing SAS Enterprise Guide to generate your ODS output (for example, SAS Report or HTML), it looks like this:

 

/* for SAS Report */
ODS tagsets.sasreport13(ID=EGSR) gtitle;

/* for HTML */
ODS HTML(ID=EGHTML) gtitle;

proc sgplot data=tme_a_data;
	title "Cost distribution for TME category='A'";
	vbarparm category=sum_category response=sum_proportion;
	xaxis tickvalueformat=dollar7. label="Cost";
	yaxis tickvalueformat=percent5. grid label="Percentage" values=(0 to .30 by .05);
run;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

9 REPLIES 9
Jagadishkatam
Amethyst | Level 16

The inset statement will work here, please try the below code

 

proc sgplot data=tme_a_data;
    vbarparm category=sum_category response=sum_proportion;
    xaxis tickvalueformat=dollar7. label="Cost";
    yaxis tickvalueformat=percent5. grid label="Percentage" values=(0 to .30 by .05);
inset (' '=  "Cost distribution for TME category='A'") / position=top;
run;

 

Thanks,
Jag
RobF
Quartz | Level 8

Thank you Jagadishkatam - I tried the inset statements but they always place the title inside of the axis area.

 

I'd like to put the title in the area between the axis area and the boundary of the entire chart area (the same area that the axis labels inhabit).

 

This may not be possible in SAS EG. The only other option which may work is to use the keylegend statement to position a title at the top outside of the axis area.

Bryan
Obsidian | Level 7

Try sganno, that is what I use get get the title on the graph.  May have to adjust x1 y1.

 


Data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
width=400;
textweight='bold';
textsize=20;
anchor='centerleft';
y1=95;
x1=50;
label="Cost distribution for TME category='A'";
output;
run;

proc sgplot data=tme_a_data
sganno=anno pad=(top=10%);
vbarparm category=sum_category response=sum_proportion;
xaxis tickvalueformat=dollar7. label="Cost";
yaxis tickvalueformat=percent5. grid label="Percentage" values=(0 to .30 by .05);
run;

RobF
Quartz | Level 8

Thanks Bryan, that did the trick.

 

I imagine SAS will update proc sgplot at some point to make title placement much simpler - the sganno fix works but doesn't it seem like a lot of code to stick a title above a chart?!

Bryan
Obsidian | Level 7

Glad I could help and I agree that it is a lot of code just to add a title in the chart.

ChrisHemedinger
Community Manager

There is a much easier way!  Use the GTITLE option on the ODS statement.  If allowing SAS Enterprise Guide to generate your ODS output (for example, SAS Report or HTML), it looks like this:

 

/* for SAS Report */
ODS tagsets.sasreport13(ID=EGSR) gtitle;

/* for HTML */
ODS HTML(ID=EGHTML) gtitle;

proc sgplot data=tme_a_data;
	title "Cost distribution for TME category='A'";
	vbarparm category=sum_category response=sum_proportion;
	xaxis tickvalueformat=dollar7. label="Cost";
	yaxis tickvalueformat=percent5. grid label="Percentage" values=(0 to .30 by .05);
run;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
RobF
Quartz | Level 8

Thanks Chris - I tried running your suggested code:

 

/* for HTML */
ODS HTML(ID=EGHTML) gtitle;

proc sgplot data=Prop_A_&bin_a;
	title "Cost distribution for TME category='A'";
	format sum_category dollar10.;
	vbarparm category=sum_category response=sum_proportion;
	xaxis tickvalueformat=dollar7. label="Cost";
	yaxis tickvalueformat=percent5. grid label="Percentage" values=(0 to .30 by .05);
run;

 

which runs successfully, but now the title is completely missing from the graph. Do I need to add anything to the ODS statement?

 

LauraRK
Quartz | Level 8

Hi.  I encountered your problem when googling for help with titles while using the SG plotting procedures.  I found this 

http://support.sas.com/documentation/cdl/en/graphref/67881/HTML/default/viewer.htm#p0ugm0gm0wjbegn15...

 

very helpful.  I think for your problem if you turn on the USEGOPT using the little bit of code below and then use Chris's solution as well it should work.  At least it worked for me.

 

ODS USEGOPT ;
djrisks
Barite | Level 11

Hi Chris,

 

Just saying thank you for providing this option:

 

/* for SAS Report */
ODS tagsets.sasreport13(ID=EGSR) gtitle;

 

I was trying to add the title on to my SGPLOTs that were created in Enterprise Guide for the last hour. And this solved the problem. This also made the plots be in the same font as the plots I previoulsy created when using SAS 9.4. Fantastic option!

 

Many thanks,


Kriss Harris

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 26655 views
  • 4 likes
  • 6 in conversation