BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
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]

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