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

Hi SAS Friends,

I have a bar chart where, for clarity, would like to decrease the relative Bar length (figure), and increase the Tick area (tick) that contains survey questions.  Would also like to change the color of the bars to dark blue.

Attached is the current output (PDF) and complete code.

Am using very helpful code from this blog, 

https://blogs.sas.com/content/graphicallyspeaking/2013/12/19/survey-charts/

which indicates the tick:figure ratio is fixed at 40%.  Can this be altered?

Would like to increase the tick area to at least 60%, because that is where the message is, in the text.  Or in some other way make it easier to read the Tick (Y-Axis) text.

Any suggestions are greatly appreciated, 

Thank you !

R

	/*--Survey Data--*/
	data survey;
	  length question $ 70;
	  input response question $8-70;
	  format response percent5.1;
	  datalines;
	0.839  Developed frog prioritization protocols to manage shortages
	0.984  Experienced disruptions due to Yogurt 
	0.915  Experienced STP shortages
	0.660  Experienced frog shortages
	0.308  Disrupted assurunity-based fractionation practice
	0.154  Disrupted assurunity-based diakinetic services
	0.840  Research yarnoacists supported Yogurt  projects
	0.793  New suppliers brought in
	0.733  Increased in-house frog inventories 
	;
	run;
	proc sort	;	by descending response 	;	run	;


	%let gpath="&Gph";
	%let dpi=200;
	ods html close;
	ods listing gpath=&gpath image_dpi=&dpi;

	proc template;
	  define statgraph Survey_GTL;
	    begingraph;
	      entrytitle 'ABCD Assurunity Survey Results';
	      layout overlay / xaxisopts=(display=(ticks tickvalues) tickvalueattrs=(size=8))
	                       yaxisopts=(reverse=true display=(ticks tickvalues) 
	                       tickvalueattrs=(size=7) discreteopts=(tickvaluefitpolicy=split));
		    barchart category=question response=response / orient=horizontal 
	                 fillattrs=graphdata2 dataskin=gloss barlabel=true;
		  endlayout;
		endgraph;
	  end;
	run;

	/*--GTL HBar with default split width--*/
	%let datetime 	= 	%sysfunc(compress(%sysfunc(today(),yymmddN8.)_%sysfunc(time(),hhmm6.), ': '));
	ods graphics / reset width=6in height=5in imagename="Survey_TEST_&datetime";
	proc sgrender data=survey template=Survey_GTL;
	run;

   

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

I would recommend using Proc SGplot, rather than Proc SGrender and a custom template.

 

Something like this:

 

title1 color=gray33 "ABCD Assurunity Survey Results";
proc sgplot data=survey noborder;
hbarparm category=question response=response / datalabel fillattrs=(color=dodgerblue);
yaxis display=(nolabel noticks);
run;

 

blue_bar.png

 

View solution in original post

4 REPLIES 4
GraphGuy
Meteorite | Level 14

I would recommend using Proc SGplot, rather than Proc SGrender and a custom template.

 

Something like this:

 

title1 color=gray33 "ABCD Assurunity Survey Results";
proc sgplot data=survey noborder;
hbarparm category=question response=response / datalabel fillattrs=(color=dodgerblue);
yaxis display=(nolabel noticks);
run;

 

blue_bar.png

 

rmacarthur
Pyrite | Level 9

Thank you Robert, much appreciated !

t75wez1
Pyrite | Level 9

Rob,

I like your simple solution using HBARPARM statement in proc sgplot.

 

We can use the HBAR statement with the CATEGORYORDER=RESPDESC which creates the chart with the descending order of the bars.

 

But how to create a bar chart using HBARPARM statement with descending response if my response variable is not pre-sorted?

 

Thanks,

Ethan

 

GraphGuy
Meteorite | Level 14

As I understand it, sgplot's "hbar" is designed to summarize multiple obsns per bar ... and therefore you can't really sort the data ahead of time ... and therefore hbar has options to let you specify the order for it to apply to the bars after the statistic is calculated. Sgplot's "hbarparm" on the other hand, is designed to be used with pre-summarized data ... and with pre-summarized data you can simply sort the dataset before running proc sgplot. (I haven't delved into this distinction too much, and users more savvy in this area might provide additional insight/corrections/clarifications to what I said - that would not hurt my feelings!) 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1030 views
  • 1 like
  • 3 in conversation