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
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;
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;
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.
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;
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?!
Glad I could help and I agree that it is a lot of code just to add a title in the chart.
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;
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?
Hi. I encountered your problem when googling for help with titles while using the SG plotting procedures. I found this
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 ;
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
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 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: