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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

 

 

View solution in original post

6 REPLIES 6
Reeza
Super User

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;

 

chetan3125
Obsidian | Level 7
Destinaition is RTF.
trying to get 2 plots in same image.
ballardw
Super User

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
Obsidian | Level 7
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.
ballardw
Super User

@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.

Ksharp
Super User

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;

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 6 replies
  • 1511 views
  • 5 likes
  • 4 in conversation