BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

I am tring to create a horizontal bar chart using sgplot I already have the chart drawn but on the yaxis where the labels are:

I will like each group to have a header. Is there an way to use annotate to make this?

e.g. I have milk, ovaltine, sugar, this is grouped under beverages

       biscuits, cake, donuts is grouped under Snacks

       chocolate, toffies, chewing gums grouped under Sweets

I have sg already plotted the graph but I want beverages, Snacks and Sweets to be bold, with border lines, and background=blue

 

 

here is my data and the program: I will appreciate any help:

 

valueordertypePercentreport_cat
Head1Beverages  
body2Milo99,6london
body2Milo100reported
body3Ovaltine84,1reported
body3Ovaltine84,7london
body4Sugar73,4london
body4Sugar93,8reported
body5Coffee70,2london
body5Coffee93,8reported
body6milk70,6london
body6milk93,8reported
body7condense milk84,8london
body7condense milk92,6reported
Head8Snacks  
body9cake15,2reported
body9cake69,1london
body10pie15,2reported
body10pie68,1london
body11biscuits15,2reported
body11biscuits68,1london
body12donuts15,2reported
body12donuts51,7london
Head13Sweets  
body14toffies reported
body14toffies70london
body15chewinggums reported
body15chewinggums68,1london
body16chocolate reported
body16chocolate55,7london

 

 

 

proc sgplot data=input  pad=(bottom=5%);
styleattrs datacolors=(green blue);
yaxis grid type=discrete discreteorder=data;
 
hbar type /response=percent  group=report_cat groupdisplay=cluster
                    barwidth=0.8 missing ;
        
yaxis display=(nolabel) offsetmin=0.05 offsetmax=0.05;
xaxis label='percentage %' grid offsetmin=0.0 offsetmax=0.05;
keylegend / location=outside position=bottomleft across=1 title="" ;

run;

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

First port of call on any graphing question is here:
https://blogs.sas.com/content/graphicallyspeaking/

 

Thousands of examples of all kinds of graphs.  One from the first page that jumped out to me as showing groupings might be this one:

https://blogs.sas.com/content/graphicallyspeaking/2016/05/30/ctspedia-clinical-graphs-subgrouped-for...

Anita_n
Pyrite | Level 9

I have tried the your suggestions but it isn't working. Pls am still counting on any other help

ballardw
Super User

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

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