BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I'm able to use "inside=sum" when I set device=activex.
However, the values don't appear and I get this warning when I switch to device=gif:
WARNING: INSIDE= and OUTSIDE= options will be ignored for HBAR charts.
How can I use "inside=sum" while using device=gif (so I can output my files as .gif)?
I create my plot using gchart and hbar/discrete.

Also, how can I increase the font size of the sum values inside the bars when I use "inside=sum"?

Thank you.
13 REPLIES 13
GraphGuy
Meteorite | Level 14
The "inside=" feature is not supported for dev=gif gchart hbars.
You'll have to annotate the values (which also means you'll have to pre-summarize the data, if it's not already summarized).

Here is some example code:

data my_anno; set sashelp.class;
xsys='2'; ysys='2'; hsys='3'; when='a';
x=weight; midpoint=name;
function='label'; position='4'; size=2;
text=trim(left(weight));
run;

proc gchart data=sashelp.class anno=my_anno;
hbar name / type=sum sumvar=weight descending nostats;
run;


There's been a request in the system to add this feature for several years (S0240334).
The more customer feedback SAS receives, the more likely it is to get added,
so I encourage you to send in some official feedback indicating that you're
interested in this feature (squeaky wheel gets the oil! 🙂
deleted_user
Not applicable
I got numbers to show up on the plot, but they're not being placed in the correct spots.

data bar6;
set bar5;
format ct percent6.0;
ct=count/total;
run;
data my_anno;
set bar6;
xsys='2'; ysys='2'; hsys='3'; when='a';
x=round(ct,.01); midpoint=role;
function='label'; position='4'; size=2;
text=trim(left(round(ct,0.01)));
run;
proc gchart data=bar6 anno=my_anno;
hbar role / discrete
nostats
type=sum sumvar=ct
subgroup=q1

"count" and "total" are both numeric.
"role" is either "Manager" or "Member".
"q1" is "Strongly Agree", "Agree", or "Disagree".

Thank you.
GraphGuy
Meteorite | Level 14
Could you elaborate a little on where the annotate text *is* showing up?
deleted_user
Not applicable
The data in bar6 is sorted as:
"Strongly Disagree", "Disagree", "Agree", "Strongly Agree"

However, gchart changes the order (to alphabetical):
"Agree", "Disagree", "Strongly Agree", "Strongly Disagree"

The numbers from my_anno would be showing up in the right place if gchart kept the same order as bar6 (instead of changing it to alphabetical).

How can I keep the order in gchart that is in bar6?

Thank you.
deleted_user
Not applicable
I was able to get the text to show up where I wanted it. It was a little bit tricky because I'm using a stacked bar chart.
"ct" is a percentage (count/total). How do I get "ct" to show up as a percentage on my gchart?
xsys='2'; ysys='2'; hsys='3'; when='a';
if(qs in (4) and ct>0) then x=0.95;
if qs in (3) then x=0.5;
if qs in (1) then x=ct;
if qs in (2) then x=ct+0.02;
midpoint=question;
function='label'; position='4'; size=3;
text=ct;

Thank you.
GraphGuy
Meteorite | Level 14
Ahh! - I hadn't noticed you're doing a *subgrouped* (stacked) bar chart!

For a subgrouped hbar chart, you use a "subgroup=" variable in your annotate data set, rather than the "x=" variable. Here's an example...

data my_anno; set sashelp.class;
xsys='2'; ysys='2'; hsys='3'; when='a';
subgroup=name; midpoint=sex;
function='label'; position='4'; size=2;
text=trim(left(weight));
run;

proc gchart data=sashelp.class anno=my_anno;
hbar sex / type=sum sumvar=weight descending subgroup=name nostats;
run;
deleted_user
Not applicable
Looks good.
How do I output percentages instead of decimals (eg 20% instead of 0.2)?
Thank you.
GraphGuy
Meteorite | Level 14
You can apply a format when you create the "text" variable.

For example, instead of ...

text=trim(left(value));

Use something like ...

text=trim(left(put(value,percent7.1)));
Cynthia_sas
SAS Super FREQ
Hi:
In addition to Robert's Annotate solution, if you use DEVICE=ACTXIMG, you are then able to use INSIDE with HBAR. The tradeoff is that you get a PNG file instead of a GIF file.

cynthia
deleted_user
Not applicable
The file does not seem to be outputting when I use:
goptions device=ACTXIMG gsfname=outfile gsfmode=replace;
filename outfile "C:\test.png";
However, a .png file shows up in the EG HTML window.

Is there a way to make a .png file output like a .gif file?
Cynthia_sas
SAS Super FREQ
Hi:
I just never use GSFNAME/GSFMODE anymore. That's because ODS HTML automatically creates an external image file and then builds an <IMG> tag which points to the location of the external image file. Then, if I don't want the HTML file, I can just ditch it and use the PNG file.

To name the PNG file, I use NAME= on the HBAR or VBAR or PLOT statement. The .PNG extension gets added automatically.

For example, if I run the code below and my working directory is set to 'c:\temp', then the code will create: c:\temp\inside.png

cynthia
[pre]

/* Define a data set for charting
Program adapted from:
http://support.sas.com/kb/24/873.html
*/

data a;
infile datalines;
input state $ sales;
return;
datalines;
NC 50
NY 10
NY 70
MA 10
MA 20
MA 30
CA 90
CA 10
CA 10
CA 20
;
run;

ods html path='.' gpath='.'
file='inside_acx.html' style=analysis;
goptions reset=all device=actximg htext=12pt;
title1 '1) ACTXIMG and Inside Option';
axis1 label=('Sales') minor=none;
axis2 label=('State');
proc gchart data=a;
title2 'With ACTXIMG device -- get INSIDE for VBAR and HBAR';
hbar state / inside=sum sumvar=sales raxis=axis1 maxis=axis2 name='inside';
run;
quit;
ods html close;
[/pre]
deleted_user
Not applicable
Thanks.
However, when the file that is outputted doesn't have a title on it.
Is there anyway to keep the title on the outputted file?
Thank you.
GraphGuy
Meteorite | Level 14
Device=activex (and actximg) does not support "gtitles" (titles within the graph area), and therefore the actximg png file does not contain the title.

This is another one of those "feature requests" that it would be good to send some official feedback to SAS, to let the development teams know there is customer interest in adding this feature. (you might reference feature request S0352870).

-

Also, when you run a device=gif or png sas/graph job as a Stored Process, it uses "nogtitles" by default, and you have to over-ride the default to change it to using "gtitles". Just thought I'd mention that, in case you go that route later.

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!

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
  • 13 replies
  • 1341 views
  • 0 likes
  • 3 in conversation