BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
uopsouthpaw
Calcite | Level 5

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.  

Vbar vline.jpg

 

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

View solution in original post

4 REPLIES 4
DanH_sas
SAS Super FREQ

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_sas
SAS Super FREQ

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

uopsouthpaw
Calcite | Level 5

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.

uopsouthpaw
Calcite | Level 5

Cancel that Dan.  nomissinggroup takes it out.  Again, thanks for the quick response and help.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1292 views
  • 0 likes
  • 2 in conversation