Data visualization with SAS programming

vbar graphs (that are not stacked) in sgplot

Reply
Regular Contributor
Regular Contributor
Posts: 170

vbar graphs (that are not stacked) in sgplot

Hello all;
The first question is,
how do I create a vertical bar graph that consists of multiple groups (RN, MD, RT,etc), ordered by month that the different groups don't end up stacked, but rather next to each other as I get when I perform such code:


proc sgplot data=AGGREGATEG;
vbar fx/ response=compliance group=type;
run;

The goal is that the compliance is the Y axis, the months are the X axis with the groups in 4 different vertical bars.

Some observations below:
Thanks

Lawrence


Obs fx COMPLIANCE DENOMS NUMY TYPE

1 JUL10 0.81250 32 26 RN
2 AUG10 0.91525 59 54 RN
3 SEP10 0.58209 134 78 RN
4 OCT10 0.43750 80 35 RN
5 JUL10 0.60000 5 3 MD
6 AUG10 0.40000 10 4 MD
7 SEP10 0.42373 59 25 MD
8 OCT10 0.30667 75 23 MD
9 JUL10 0.00000 2 0 RT
10 AUG10 0.66667 3 2 RT
11 SEP10 1.00000 2 2 RT
12 OCT10 0.66667 3 2 RT
13 JUL10 0.81250 16 13 OT
14 AUG10 0.85000 20 17 OT
15 SEP10 0.23913 46 11 OT
16 OCT10 0.48485 33 16 OT
SAS Employee
Posts: 980

Re: vbar graphs (that are not stacked) in sgplot

Sounds like you want a "grouped bar chart" ... I would recommend using good-old "proc gchart" - perhaps something like the following:

data mydata;
length type $2.;
format fx monyy7.;
format compliance percent7.0;
input fx date7. compliance denoms numy type;
datalines;
15JUL10 0.81250 32 26 RN
15AUG10 0.91525 59 54 RN
15SEP10 0.58209 134 78 RN
15OCT10 0.43750 80 35 RN
15JUL10 0.60000 5 3 MD
15AUG10 0.40000 10 4 MD
15SEP10 0.42373 59 25 MD
15OCT10 0.30667 75 23 MD
15JUL10 0.00000 2 0 RT
15AUG10 0.66667 3 2 RT
15SEP10 1.00000 2 2 RT
15OCT10 0.66667 3 2 RT
15JUL10 0.81250 16 13 OT
15AUG10 0.85000 20 17 OT
15SEP10 0.23913 46 11 OT
15OCT10 0.48485 33 16 OT
;
run;

axis1 label=('Compliance') order=(0 to 1 by .2) minor=none offset=(0,0);
axis2 label=none offset=(3,3);
axis3 label=none;

proc gchart data=mydata;
vbar type / discrete type=sum sumvar=compliance
group=fx raxis=axis1 maxis=axis2 gaxis=axis3;
run;
SAS Super FREQ
Posts: 925

Re: vbar graphs (that are not stacked) in sgplot

Here are a few variations you can use using SGPANEL:

[pre]
proc sgpanel data=AGGREGATEG;
panelby type / onepanel noborder layout=columnlattice;
vbar fx/ response=compliance;
run;
[/pre]

[pre]
proc sgpanel data=AGGREGATEG;
panelby type / onepanel noborder layout=rowlattice;
hbar fx/ response=compliance;
run;
[/pre]

[pre]
proc sgpanel data=AGGREGATEG;
panelby type; /* optionally add ROWS, COLUMNS, or ONEPANEL */
vbar fx/ response=compliance;
run;
[/pre]

For the first two, you can also move the header down and use a legend:

[pre]
proc sgpanel data=AGGREGATEG;
panelby type / onepanel noborder layout=columnlattice colheaderpos=bottom;
vbar fx/ response=compliance group=type;
run;
[/pre]

[pre]
proc sgpanel data=AGGREGATEG;
panelby type / onepanel noborder layout=rowlattice rowheaderpos=left;
hbar fx/ response=compliance group=type;
run;
[/pre]

Let me know if this is what you're after.

Thanks!
Dan
Regular Contributor
Regular Contributor
Posts: 170

Re: vbar graphs (that are not stacked) in sgplot

Dan & Robert;
Thank you both for your suggestions. It gets me going but I am going to have to do a lot of manipulations...

But Robert, or Dan

so I am going to have an compliance overall rate at some juncture as a vline with the datalabels in big fat yellow bubbles connected by a line. I'd rather concatenate the overall rate with the month but mgmt will not go along with that idea.

I am just attempting to free up the other analyst, as the data above represents only 1 of 40 units that have to be graphed in Excel manually.

Thanks

Lawrence
SAS Employee
Posts: 980

Re: vbar graphs (that are not stacked) in sgplot

You can do that in 'gchart' using annotate.

The yellow bubble can be done with function='pie' and the text can be done with function='label'.
Regular Contributor
Regular Contributor
Posts: 170

Re: vbar graphs (that are not stacked) in sgplot

Thanks Robert!
SAS Super FREQ
Posts: 1,141

Re: vbar graphs (that are not stacked) in sgplot

Can you attach an image to indicate what you want?
Regular Contributor
Regular Contributor
Posts: 170

Re: vbar graphs (that are not stacked) in sgplot

Sanjay;
I wish I could do that, but this forum does not allow for that..
Ask a Question
Discussion stats
  • 7 replies
  • 317 views
  • 0 likes
  • 4 in conversation