Hi ,
I am trying to get 2 bar charts for Asia and Europe side by side in one page in following sample data.
Can someone please suggest an option to do this ?
I am new to figures and don't know how to subset the data for each region and get the bar charts side by side.
Thanks.
proc template;
define statgraph multiple_charts;
begingraph;
entrytitle "two Charts in One Image";
/* Define Chart Grid */
layout lattice / rows = 1 columns = 2;
/* Chart 1 is for Europe */
layout overlay;
entry "Barchart" / location=outside;
barchart x=DriveTrain y=msrp;
endlayout;
/* Chart 2 is for Asia */
layout overlay;
entry "Barchart" / location=outside;
barchart x=DriveTrain y=msrp;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.cars template=multiple_charts;
/*where origin in ('Asia' , 'Europe') ;*/
run;
Change your data structure ?
proc template;
define statgraph multiple_charts;
begingraph;
entrytitle "two Charts in One Image";
/* Define Chart Grid */
layout lattice / rows = 1 columns = 2;
/* Chart 1 is for Europe */
layout overlay;
entry "Asia's Barchart" / location=outside;
barchart x=DriveTrain y=Asia;
endlayout;
/* Chart 2 is for Asia */
layout overlay;
entry "Europe's Barchart" / location=outside;
barchart x=DriveTrain y=Europe;
endlayout;
endlayout;
endgraph;
end;
run;
proc sort data= sashelp.cars(where=(origin in ('Asia' , 'Europe'))) out=cars(keep=origin DriveTrain msrp);
by DriveTrain origin ;
run;
proc transpose data=cars out=temp;
by DriveTrain origin;
var msrp;
run;
proc transpose data=temp out=temp2;
by DriveTrain ;
id origin;
var col:;
run;
proc sgrender data=temp2 template=multiple_charts;
run;
What is your ultimate output destination? HTML/RTF/PDF?
Do they have to be two plots in one image or would two plots on the same page is enough?
@chetan3125 wrote:
Hi ,
I am trying to get 2 bar charts for Asia and Europe side by side in one page in following sample data.Can someone please suggest an option to do this ?
I am new to figures and don't know how to subset the data for each region and get the bar charts side by side.
Thanks.
proc template; define statgraph multiple_charts; begingraph; entrytitle "two Charts in One Image"; /* Define Chart Grid */ layout lattice / rows = 1 columns = 2; /* Chart 1 is for Europe */ layout overlay; entry "Barchart" / location=outside; barchart x=DriveTrain y=msrp; endlayout; /* Chart 2 is for Asia */ layout overlay; entry "Barchart" / location=outside; barchart x=DriveTrain y=msrp; endlayout; endlayout; endgraph; end; run; proc sgrender data=sashelp.cars template=multiple_charts; /*where origin in ('Asia' , 'Europe') ;*/ run;
What details do you need that Sgpanel doesn't give you?
proc sgpanel data=sashelp.cars; where origin in ('Asia' 'Europe'); panelby origin/ columns=2; vbar drivetrain / response=msrp; run;
@chetan3125 wrote:
Thanks for this. but my company has a specific styles for graphs. which works with Proc template.
Hence , I was trying to do this without changing much in the code which we already have.
Okay, company policy I understand.
Suggestion: when asking questions about graphic output provide a picture of the results needed as well as likely/possibly optional appearance needs that may be required sometimes (such as Fonts, standard color lists/orders). Knowing the actual desired appearance means we can make more targeted solutions. A list of likely needed options may head-off approaches that work for the provided example data set but may not work for the "simple" addition of one more graph that goes on a second row.
Change your data structure ?
proc template;
define statgraph multiple_charts;
begingraph;
entrytitle "two Charts in One Image";
/* Define Chart Grid */
layout lattice / rows = 1 columns = 2;
/* Chart 1 is for Europe */
layout overlay;
entry "Asia's Barchart" / location=outside;
barchart x=DriveTrain y=Asia;
endlayout;
/* Chart 2 is for Asia */
layout overlay;
entry "Europe's Barchart" / location=outside;
barchart x=DriveTrain y=Europe;
endlayout;
endlayout;
endgraph;
end;
run;
proc sort data= sashelp.cars(where=(origin in ('Asia' , 'Europe'))) out=cars(keep=origin DriveTrain msrp);
by DriveTrain origin ;
run;
proc transpose data=cars out=temp;
by DriveTrain origin;
var msrp;
run;
proc transpose data=temp out=temp2;
by DriveTrain ;
id origin;
var col:;
run;
proc sgrender data=temp2 template=multiple_charts;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.