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

HI All,

I have a horizontal bar chart that has very long data labels so that the chart itself is truncated. Is there a way to either wrap the text or expand the right side of the graph?

I used proc sgplot because I want the groups to be stacked on top of one another, which I don't think is possible in proc gchart.

Please see have.png for what the chart looks like and want.png as an example of how I'd like it to look.

Thanks!

Sarah


have.pngwant.PNG
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

If you don't find an sgplot solution, here's how to do it in gchart (I don't seem to be able to copy-n-paste legibly into here today, so see attached foo.sas) ...

View solution in original post

11 REPLIES 11
GraphGuy
Meteorite | Level 14

If you don't find an sgplot solution, here's how to do it in gchart (I don't seem to be able to copy-n-paste legibly into here today, so see attached foo.sas) ...

sarahsasuser
Quartz | Level 8

Thanks Robert! This works.

sarahsasuser
Quartz | Level 8

Hi Robert,

I'm having an issue with ordering the data using the split option. I'd like the chart to be in descending order, but when I add that option (in bold) the split stops working. Any suggestions?

Thanks!

Sarah

axis1 label=none value=none;

axis2 label=none value=(justify=right) split='\' order=descending;

proc gchart data=foo;

hbar colorvar / discrete type=sum sumvar=my_value subgroup=colorvar

group=label space=0 maxis=axis1 gaxis=axis2;

run; quit;

GraphGuy
Meteorite | Level 14

"order=descending" is not a valid option to put on the axis statement.  The log shows the following...

332  axis2 label=none value=(justify=right) split='\' order=descending;
                                                            ----------
                                                            22
                                                            76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
              a datetime constant, (.

ERROR 76-322: Syntax error, statement will be ignored.

sarahsasuser
Quartz | Level 8

Thanks Robert. How do I get the data in the order I want it in? I want to reorder the group variable by descending. I've sorted the data by the group variable before running the chart and that doesn't work. I've added the descending option to the options after the '/' in the hbar statement and that doesn't work either.

Thanks,

Sarah

GraphGuy
Meteorite | Level 14

The 'descending' option orders by bar heights, not the labels.

To sort the groups in a certain order, you'll either have to hard-code the values in the order= of the group's axis statement, such as ...

axis2 order=('the group I want first' 'the group I want second' 'and so on');

Or you could assign numeric values to correspond to the groups, and make those numeric values in the order you want, and plot them instead of the text groups ... and then use a user-defined-format to make those numeric values show up as the text values.

Or, if you're not too picky about the exact text, you might could pre-pend something that will help you force the default alphabetical order to sort in the way you want (such as pre-pending a '1: ' and a '2:', and so on) in front of your text values.

Also, there's a bug related to specifying custom order for values >32 characters in SAS 9.2 ... this bug is fixed in SAS 9.3 - hopefully you're using 9.3! Smiley Happy

sarahsasuser
Quartz | Level 8

Thanks, I used the order= option in the axis statement. Luckily, I do have 9.3! I found that if I used formats then SAS will order by the alphabetical order of the format, not the underlying value. And I had to wrap the text, and the split statement doesn't work with formats. Please correct me if I'm wrong. Thanks for your help!

Sarah

GraphGuy
Meteorite | Level 14

Ahh - now that I think about it, you are correct!  For bar charts, the bar ordering is done on the formatted value, rather than the underlying numeric value.  I had entered a 'bug' on that in 2005, but the developers say it's working as intended Smiley Happy

Jay54
Meteorite | Level 14

Yes, you can make a stacked group bar chart with GCHART.  Use SUBGROUP option.  With SGPLOT you can use HBAR to place labels from another variable, but there is no way to automatically wrap long data Labels.  If you can split the labels yourself, you can use SGANNO.

sarahsasuser
Quartz | Level 8

Hi Sanjay,

I am curious about SGANNO. I know how to add that to the sgplot procedure, but I don't know how to format the annotated dataset so that this will work properly. Can you point me to an example?

Thanks,

Sarah

Jay54
Meteorite | Level 14

Here is an article using SGANNO.  It works mostly like annotate, with a few differences.  i suggest you look up the doc, or Ch 9 of the SGPROCEDURES book.  The TEXT function wraps text within the specified width.  So you don't have to split the text, just specify a wrapping width.


Risk tables, annotated or not - Graphically Speaking

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
  • 11 replies
  • 8883 views
  • 5 likes
  • 3 in conversation