Hello,
I'm attempting to create a Vbar chart that has an overlay of a vline on the secondary axis. The problem I run into is that the vbar is broken into sub-groups, while the vline is in main groups. E.g vbar is Product A - Model 1, Product A - Model 2, Product B - Model 1, Product B - Model 2, while vlinen is Product A, Product - B. The graph was created in Excel, but I am trying to automate through SAS.
Any suggestions on how to approach this? I get an error stating that once a group has been invoked, all further overlays must also invoke the group.
Thanks.
For this situation, you'll need to use a vbarparm/series combination instead of vbar/vline. You'll need to precompute your data before graphing it. The example below computes the data for each plot, merges the data into one data set, and plots it with SGPLOT.
proc summary data=sashelp.prdsale nway;
class product region;
var actual;
output out=bars sum=;
run;
proc summary data=sashelp.prdsale nway;
class product;
var predict;
output out=line sum=;
run;
data merged;
merge bars line (rename=(product=product2));
run;
ods listing close;
proc sgplot data=merged;
y2axis min=0;
vbarparm category=product response=actual / group=region;
series x=product2 y=predict / y2axis lineattrs=(thickness=3);
run;
Hope this helps!
Dan
For this situation, you'll need to use a vbarparm/series combination instead of vbar/vline. You'll need to precompute your data before graphing it. The example below computes the data for each plot, merges the data into one data set, and plots it with SGPLOT.
proc summary data=sashelp.prdsale nway;
class product region;
var actual;
output out=bars sum=;
run;
proc summary data=sashelp.prdsale nway;
class product;
var predict;
output out=line sum=;
run;
data merged;
merge bars line (rename=(product=product2));
run;
ods listing close;
proc sgplot data=merged;
y2axis min=0;
vbarparm category=product response=actual / group=region;
series x=product2 y=predict / y2axis lineattrs=(thickness=3);
run;
Hope this helps!
Dan
For this situation, you'll need to use a vbarparm/series combination instead of vbar/vline. You'll need to precompute your data before graphing it. The example below computes the data for each plot, merges the data into one data set, and plots it with SGPLOT.
proc summary data=sashelp.prdsale nway;
class product region;
var actual;
output out=bars sum=;
run;
proc summary data=sashelp.prdsale nway;
class product;
var predict;
output out=line sum=;
run;
data merged;
merge bars line (rename=(product=product2));
run;
ods listing close;
proc sgplot data=merged;
y2axis min=0;
vbarparm category=product response=actual / group=region;
series x=product2 y=predict / y2axis lineattrs=(thickness=3);
run;
Hope this helps!
Dan
DanH thanks for the response. Works 99% of the way. I have my stacked (by group A) vbars and my series (by group B - 2 subsets) running across the chart, however, there is a third line that appears in the Keylegend ( a phantom 3rd series). I don't see any additonal values in my data set. Ideas on what is causing this? The phantom doesn't show up on your example if I split up the series into groups.
Cancel that Dan. nomissinggroup takes it out. Again, thanks for the quick response and help.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.