Data visualization with SAS programming

Stacked bar chart

Accepted Solution Solved
Reply
Super Contributor
Posts: 255
Accepted Solution

Stacked bar chart

[ Edited ]

chart.PNG

 

Hello

 

I'm trying to create a chart as above but I'm not able to do it when the data is split by new business and renewal. I have attached my dataset and here is the code I have used where the data is not split by new bus/renewal

 

proc sgplot data=testsum ;

title bold height = 1.5 "aptp";

vbar period / response=PolCountfillattrs=(color = DEPPK ) legendlabel = "policy count";

vline period / response=APTP y2axis lineattrs=(color=blb thickness = 2) legendlabel = "APTP";

yaxis label = "vehicle exposure years" labelattrs=(weight=bold size = 10);

y2axis label = "APTP" labelattrs=(weight=bold size = 10);;

xaxis display = (nolabel) ;

run;

 

 

 


Accepted Solutions
Solution
‎12-04-2015 10:09 AM
SAS Super FREQ
Posts: 864

Re: Stacked bar chart

Just remove the GROUPDISPLAY option. I think you will get the cluster effect by default.

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 6,704

Re: Stacked bar chart

I believe you are looking for the group= option:

https://support.sas.com/documentation/cdl/en/grstatproc/65235/HTML/default/viewer.htm#n0p7vdd69sgf3w...

There is also a typo:

response=PolCountfillattrs

Should have space before fill.

SAS Super FREQ
Posts: 864

Re: Stacked bar chart

Generally, you can use the GROUP option, as mentioned by RW9; however, in this case, you'll need to do a little more. In your example, you have two categorical charts overlaid with different group variables ("categorical" meaning a VBAR/HBAR, VLINE/HLINE, or DOT). There is currently a restriction on those charts in that you can use only one group variable, and it must apply to all overlays. However, there is a workaround where you can do the calcuations using PROC MEANS, merge the data, and use VBARPARM and SERIES instead. I made a simple example below. Let me know if you have any questions.

 

Thanks!

Dan

 

proc means data=sashelp.class nway;
class sex age;
var weight;
output out=temp1 mean=weight_mean;
run;

 

proc means data=sashelp.class nway;
class sex age;
var height;
output out=temp2 mean=height_mean;
run;

 

proc sort data=temp1; by sex age; run;
proc sort data=temp2; by sex age; run;

 

data merged;
merge temp1 temp2 (keep=sex age height_mean);
by sex age;
run;

 

Title "A Bar-line Chart";
proc sgplot data=merged;
y2axis min=0 offsetmin=0;
yaxis offsetmin=0;
vbarparm category=age response=height_mean / group=sex groupdisplay=cluster name="bar";
series x=age y=weight_mean / group=sex lineattrs=(thickness=3) y2axis name="line";
keylegend "bar" "line";
run;

 

Super Contributor
Posts: 255

Re: Stacked bar chart

error.PNG

 

 

Hi Dan

 

Thanks for your help, however, I'm getting this error when I run the code.

Solution
‎12-04-2015 10:09 AM
SAS Super FREQ
Posts: 864

Re: Stacked bar chart

Just remove the GROUPDISPLAY option. I think you will get the cluster effect by default.

Super Contributor
Posts: 255

Re: Stacked bar chart

Many thanks for your help Dan (and RW9)

Post a Question
Discussion Stats
  • 5 replies
  • 488 views
  • 0 likes
  • 3 in conversation