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;
Just remove the GROUPDISPLAY option. I think you will get the cluster effect by default.
I believe you are looking for the group= option:
There is also a typo:
response=PolCountfillattrs
Should have space before fill.
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;
Hi Dan
Thanks for your help, however, I'm getting this error when I run the code.
Just remove the GROUPDISPLAY option. I think you will get the cluster effect by default.
Many thanks for your help Dan (and RW9)
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!
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.