The SAS Output Delivery System and reporting techniques

Adding pattern on VBAR statement in PROC SGPLOT

Reply
N/A
Posts: 0

Adding pattern on VBAR statement in PROC SGPLOT

I need some help to customized the bar graphs in PROC SGPLOT.

Which option shall I use to change the default to pattern and/ or color pattern bar? Can I add the count number on top of each bar? If so, how to do it? I know PROC GCHART could do it but not sure how it might works in SGPLOT.

Thanks!
Michael.
Super Contributor
Super Contributor
Posts: 3,174

Re: Adding pattern on VBAR statement in PROC SGPLOT

Here's a good starting point with the SAS-hosted documentation references found on the SAS support http://support.sas.com/ website:

The SGPLOT Procedure
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/sgplot-chap.htm

Also, there are SAS technical and conference papers available on the website demonstrating different functions, features and capabilities with SGPLOT, as I found using the Google advanced search argument:

sgplot vbar axis site:sas.com


Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,744

Re: Adding pattern on VBAR statement in PROC SGPLOT

Hi:
I believe that you can change the color of the bar, but not the pattern (at this time).

To add the number/statistic at the top of the bar, use the datalabel option. To control the colors for a single group, see example #1 (basically, you tell it that the X axis variable is its own group. To control the colors for a grouped bar chart, use a style template, such as that shown in #2.

For more information about style elements, refer to:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/a003121053.htm
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/a003136924.htm

cynthia

[pre]
ods listing style=listing;

proc sort data=sashelp.class out=class;
by age sex;
run;

** 1 -- different color each discrete age, by using;
** age as a group;
proc sgplot data=class;
title '1) different color each age';
vbar age / datalabel stat=freq group=age;
xaxis label = 'Age'
values=(11 to 16 by 1);
yaxis label = 'Students' values=( 0 to 10 by 1);
format age 2.0;
run;

** 2 -- control colors for groups using style template;
proc template;
define style styles.mystyle;
parent = styles.listing;
class GraphColors /
'gdata1' = purple
'gdata2' = pink;
end;
run;

ods listing style=mystyle;

proc sgplot data=class;
title '2) different color for each group';
vbar age / datalabel group=sex;
xaxis label = 'Age' fitpolicy=stagger
values=(11 to 16 by 1);
yaxis label = 'Students' values=( 0 to 10 by 1);
run;

ods listing style=listing;
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 153 views
  • 0 likes
  • 3 in conversation