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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 3 replies
  • 1396 views
  • 0 likes
  • 2 in conversation