BookmarkSubscribeRSS Feed
Ture
SAS Employee
Hi! I need you help! I'm trying to use the proc sgplot in order to plot 3 variables: 1 with a line, and the other 2 variable with grouped vertical bars (no stacked). I've tried several ways but i can´t get what I need... this is my code:

proc sgplot data=work.subset;
title "Budget and sales";
vbar month/ response=sales_A ;
vbar month/ response=sales_B;
vline month/ response=sales_acum y2axis;

run;
3 REPLIES 3
Jay54
Meteorite | Level 14
Can you post the code for your data set?
Jay54
Meteorite | Level 14
You seem to have 3 separate columns. With this data structure, you have a couple of options. With SAS (TS2M3), you can get the bars side by side using GTL. Else, you can get overlaid bars. See code below. The DISCRETEOFFSET option in GTL will not work for a SAS release prior to TS2M3.

Side-by-side grouped bar charts are coming with SAS 9.3.


data subset;
input month $ sales_a sales_b sales_acum;
datalines;
Jan 200 300 500
Feb 300 400 700
Mar 200 400 600
;
run;
proc print;run;

/*--SGPLOT--*/
ods graphics / width=4in height=3in imagename='BarsSG';
proc sgplot data=work.subset;
title "Budget and Sales";
vbar month/ response=sales_A nostatlabel;
vbar month/ response=sales_B barwidth=0.6 nostatlabel;
vline month/ response=sales_acum y2axis lineattrs=(pattern=solid thickness=4) nostatlabel;
yaxis offsetmin=0;
xaxis discreteorder=data;
run;

/*--GTL--*/
proc template;
define statgraph bars;
begingraph;
entrytitle "Budget and Sales";
layout overlay / yaxisopts=(offsetmin=0);
barchart x=month y=sales_a / discreteoffset=-0.2 barwidth=0.4 fillattrs=graphdata1 name='a';
barchart x=month y=sales_b / discreteoffset= 0.2 barwidth=0.4 fillattrs=graphdata2 name='b';
seriesplot x=month y=sales_acum / lineattrs=graphdata3(pattern=solid thickness=4) yaxis=y2 name='c';
discretelegend 'a' 'b' 'c';
endlayout;
endgraph;
end;
run;

ods graphics / width=4in height=3in imagename='BarsGTL';
proc sgrender data=work.subset template=bars;
run;
Ture
SAS Employee
Thanks for your example! it was quite helpful. I've tried both options and the second is the best. Regards!

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1775 views
  • 0 likes
  • 2 in conversation