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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 9 replies
  • 23437 views
  • 4 likes
  • 6 in conversation