## VBAR with 2 bars and three lines (separate the bars)

Solved
Frequent Contributor
Posts: 129

# VBAR with 2 bars and three lines (separate the bars)

Hi All,

I have created a combo graph that has two bars and three lines, however the second bar sits behind the first one.

How do I get them to sit side by side to each other?

``````Data test;
Input WEEK_END_DT \$ TransA TransB PCTA PCTB PCTC;
Datalines;
A 5063 3487 0.170074793 0.133479212 0.282554088
B 8094 9028 0.146952298 0.097315235 0.270777721
C 9512 10226 0.144833102 0.095077215 0.282205541
D 11004 11326 0.163079597 0.107464086 0.328004634
E 10591 10351 0.171097567 0.112158341 0.370088312
F 14045 11853 0.166789031 0.113834383 0.371648951
G 14643 10257 0.158547224 0.113666708 0.363375492
H 15739 7427 0.157418355 0.124353109 0.36062151
I 16056 6942 0.156742205 0.126345609 0.353372359
J 15074 6714 0.145029987 0.115199731 0.346439628
K 15014 4723 0.136847725 0.11575052 0.325365114
L 13918 5926 0.142005567 0.113826324 0.339268335
M 14402 4526 0.132393263 0.111817638 0.319429741
N 12071 2903 0.129682074 0.113615828 0.314756587

RUN;

Proc SGPlot data=Test;
Title "Overal Transfers";
VBAR WEEK_END_DT / Response=TransA Fillattrs=(Color=BIBG ) groupdisplay=stack  Legendlabel='IIE Transfers';
VBAR WEEK_END_DT / Response=TransB Fillattrs=(Color=VIPK )groupdisplay=stack Legendlabel='NON IIE Transfers';;

VLine WEEK_END_DT / response=PCTA y2axis lineattrs=(color=darksalmon thickness=5) Legendlabel='Total Transfer %';
VLine WEEK_END_DT / response=PCTB y2axis lineattrs=(color=Blue thickness=5) Legendlabel='NON IIETransfer %';
VLine WEEK_END_DT / response=PCTC y2axis lineattrs=(color=Green thickness=5) Legendlabel='IIE Transfer %';
Yaxis values=(0 to 20000 by 2000);
y2axis values=(0 to .50 by .02) Label='Trans %';
format PCTA PCTB PCTC Percent.;
Run;``````

What I get                                         What I would like.

Any help appreciated.

Cheers

Dean

Accepted Solutions
Solution
‎04-03-2018 06:49 PM
PROC Star
Posts: 1,400

## Re: VBAR with 2 bars and three lines (separate the bars)

Something like this? Use VBARPARM instead of VBAR and SERIES instead of VLINE

``````Data test;
Input WEEK_END_DT\$ Trans AorB\$ PCTA PCTB PCTC;
Datalines;
A 5063 A 0.170074793 0.133479212 0.282554088
A 3487 B 0.170074793 0.133479212 0.282554088
B 8094 A 0.146952298 0.097315235 0.270777721
B 9028 B 0.146952298 0.097315235 0.270777721
C 9512 A 0.144833102 0.095077215 0.282205541
C 10226 B 0.144833102 0.095077215 0.282205541
D 11004 A 0.163079597 0.107464086 0.328004634
D 11326 B 0.163079597 0.107464086 0.328004634
E 10591 A 0.171097567 0.112158341 0.370088312
E 10351 B 0.171097567 0.112158341 0.370088312
F 14045 A 0.166789031 0.113834383 0.371648951
F 11853 B 0.166789031 0.113834383 0.371648951
G 14643 A 0.158547224 0.113666708 0.363375492
G 10257 B 0.158547224 0.113666708 0.363375492
H 15739 A 0.157418355 0.124353109 0.36062151
H 7427 B 0.157418355 0.124353109 0.36062151
I 16056 A 0.156742205 0.126345609 0.353372359
I 6942 B 0.156742205 0.126345609 0.353372359
J 15074 A 0.145029987 0.115199731 0.346439628
J 6714 B 0.145029987 0.115199731 0.346439628
K 15014 A 0.136847725 0.11575052 0.325365114
K 4723 B 0.136847725 0.11575052 0.325365114
L 13918 A 0.142005567 0.113826324 0.339268335
L 5926 B 0.142005567 0.113826324 0.339268335
M 14402 A 0.132393263 0.111817638 0.319429741
M 4526 B 0.132393263 0.111817638 0.319429741
N 12071 A 0.129682074 0.113615828 0.314756587
N 2903 B 0.129682074 0.113615828 0.314756587
RUN;

Title "Overal Transfers";
proc sgplot data=test noborder;
vbarparm category=WEEK_END_DT response=Trans / group=AorB groupdisplay=cluster baselineattrs=(thickness=0) name='a';
series x=WEEK_END_DT y=PCTA / y2axis lineattrs=(color=darksalmon thickness=5) name='b';
series x=WEEK_END_DT y=PCTB / y2axis lineattrs=(color=Blue thickness=5) name='c';
series x=WEEK_END_DT y=PCTC / y2axis lineattrs=(color=Green thickness=5) name='d';
xaxis discreteorder=data display=(noline nolabel noticks);
yaxis display=(noline noticks) grid values=(0 to 20000 by 2000) offsetmin=0;
y2axis display=(noline noticks) values=(0 to .40 by .04) Label='Trans %' offsetmin=0;
keylegend 'a' 'b' 'c' 'd';
format PCTA PCTB PCTC Percent.;
run;``````

All Replies
PROC Star
Posts: 1,400

## Re: VBAR with 2 bars and three lines (separate the bars)

This task is a lot easier if you gather your Trans A/B variables in one variable Trans and create some categorical variable AorB that has values  A/B.

Then use a single VBAR Statement and specify group=AorB and groupdisplay=cluster

This link may be of help

https://blogs.sas.com/content/graphicallyspeaking/2016/11/27/getting-started-sgplot-part-2-vbar/

Solution
‎04-03-2018 06:49 PM
PROC Star
Posts: 1,400

## Re: VBAR with 2 bars and three lines (separate the bars)

Something like this? Use VBARPARM instead of VBAR and SERIES instead of VLINE

``````Data test;
Input WEEK_END_DT\$ Trans AorB\$ PCTA PCTB PCTC;
Datalines;
A 5063 A 0.170074793 0.133479212 0.282554088
A 3487 B 0.170074793 0.133479212 0.282554088
B 8094 A 0.146952298 0.097315235 0.270777721
B 9028 B 0.146952298 0.097315235 0.270777721
C 9512 A 0.144833102 0.095077215 0.282205541
C 10226 B 0.144833102 0.095077215 0.282205541
D 11004 A 0.163079597 0.107464086 0.328004634
D 11326 B 0.163079597 0.107464086 0.328004634
E 10591 A 0.171097567 0.112158341 0.370088312
E 10351 B 0.171097567 0.112158341 0.370088312
F 14045 A 0.166789031 0.113834383 0.371648951
F 11853 B 0.166789031 0.113834383 0.371648951
G 14643 A 0.158547224 0.113666708 0.363375492
G 10257 B 0.158547224 0.113666708 0.363375492
H 15739 A 0.157418355 0.124353109 0.36062151
H 7427 B 0.157418355 0.124353109 0.36062151
I 16056 A 0.156742205 0.126345609 0.353372359
I 6942 B 0.156742205 0.126345609 0.353372359
J 15074 A 0.145029987 0.115199731 0.346439628
J 6714 B 0.145029987 0.115199731 0.346439628
K 15014 A 0.136847725 0.11575052 0.325365114
K 4723 B 0.136847725 0.11575052 0.325365114
L 13918 A 0.142005567 0.113826324 0.339268335
L 5926 B 0.142005567 0.113826324 0.339268335
M 14402 A 0.132393263 0.111817638 0.319429741
M 4526 B 0.132393263 0.111817638 0.319429741
N 12071 A 0.129682074 0.113615828 0.314756587
N 2903 B 0.129682074 0.113615828 0.314756587
RUN;

Title "Overal Transfers";
proc sgplot data=test noborder;
vbarparm category=WEEK_END_DT response=Trans / group=AorB groupdisplay=cluster baselineattrs=(thickness=0) name='a';
series x=WEEK_END_DT y=PCTA / y2axis lineattrs=(color=darksalmon thickness=5) name='b';
series x=WEEK_END_DT y=PCTB / y2axis lineattrs=(color=Blue thickness=5) name='c';
series x=WEEK_END_DT y=PCTC / y2axis lineattrs=(color=Green thickness=5) name='d';
xaxis discreteorder=data display=(noline nolabel noticks);
yaxis display=(noline noticks) grid values=(0 to 20000 by 2000) offsetmin=0;
y2axis display=(noline noticks) values=(0 to .40 by .04) Label='Trans %' offsetmin=0;
keylegend 'a' 'b' 'c' 'd';
format PCTA PCTB PCTC Percent.;
run;``````
Frequent Contributor
Posts: 129

## Re: VBAR with 2 bars and three lines (separate the bars)

Thanks @draycut

Works a treat.

Cheers

Dean

☑ This topic is solved.