Desktop productivity for business analysts and programmers

Locating titles inside of chart area in proc sgplot

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 81
Accepted Solution

Locating titles inside of chart area in proc sgplot

 

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


Accepted Solutions
Solution
‎05-08-2017 09:19 AM
Community Manager
Posts: 2,692

Re: Locating titles inside of chart area in proc sgplot

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;

View solution in original post


All Replies
Super User
Posts: 1,102

Re: Locating titles inside of chart area in proc sgplot

[ Edited ]

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
Frequent Contributor
Posts: 81

Re: Locating titles inside of chart area in proc sgplot

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.

Contributor
Posts: 28

Re: Locating titles inside of chart area in proc sgplot

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;

Frequent Contributor
Posts: 81

Re: Locating titles inside of chart area in proc sgplot

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

Contributor
Posts: 28

Re: Locating titles inside of chart area in proc sgplot

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

Solution
‎05-08-2017 09:19 AM
Community Manager
Posts: 2,692

Re: Locating titles inside of chart area in proc sgplot

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;
Frequent Contributor
Posts: 81

Re: Locating titles inside of chart area in proc sgplot

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?

 

Occasional Contributor
Posts: 12

Re: Locating titles inside of chart area in proc sgplot

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 ;
Super Contributor
Posts: 252

Re: Locating titles inside of chart area in proc sgplot

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 1990 views
  • 3 likes
  • 6 in conversation