Learning SAS? Welcome to the exclusive online community for all SAS learners.

Multiple graphs on one page

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Multiple graphs on one page

Hi, I was wondering how to plot multiple graphs (say histograms) on a single page without having to use SAS Graph (all I have access to is SAS university edition). Thanks!

Accepted Solutions
Solution
‎11-22-2015 04:58 PM
SAS Super FREQ
Posts: 683

Re: Multiple graphs on one page

Hi

 

You can use the ODS LAYOUT functionality to achieve what you want. The sample code below creates just a PDF file in your "MyFolder" location when using SAS University Edition. I added some comments to the code, that should get you started.

 

Attached find the PDF generated by this example code

 

Bruno

 


* close all open ODS destinations ;
ods _all_ close;

* set papersize etc. for PDF ;
options papersize="ISO A4" orientation=portrait;

* open PDF destination 
* the &_SASWS_ macro var is pointing to your "MyFolders" location
*;
ods pdf file="&_sasws_/sample.pdf";

* set size of graphics ;
ods graphics / width=8cm height=6cm;

* start gridded layout with two columns ;
ods layout gridded columns=2 ;

* generate output for first region ;
ods region;
proc sgplot data=sashelp.class;
  vbox age / group=sex;
run;

* generate output for second region;
ods region;
proc sgplot data=sashelp.class;
  histogram age;
run;

ods region;
proc sgplot data=sashelp.cars;
  vbox invoice / group=type;
run;


ods region;
proc sgplot data=sashelp.cars;
  histogram horsepower;
run;

ods layout end;

ods pdf close;

View solution in original post


All Replies
SAS Super FREQ
Posts: 683

Re: Multiple graphs on one page

Which output format (HTML, PDF, ...) would you like to use?

 

Do you want several histograms in one image or several histogram images side by side?

 

Have you hat a look at the recommendations on the right hand side of your post, that shows similars question to yours an some have beeen answered.

 

Bruno

Frequent Contributor
Posts: 108

Re: Multiple graphs on one page

Hi ,

If your data somewhat looks like mine, then try this.The options used here can be find easily.So i am not explaining them 

data histo;
input Gender$ Grade;
datalines;
Male 42
Male 43
Male 44
Male 45
Male 46
Male 47
Male 47
Male 47
Male 47
Female 50
Female 51
Female 51
Female 51
Female 51
Female 52
Female 53
Female 53
Female 53
Female 54
Female 55
;
run;
proc univariate data=histo noprint;
class Gender;
histogram Grade / midpoints=40 to 60 by 1 vscale=count vaxis=0 to 10 by 1
vaxislabel= 'Frequency' 
cframe=ligrU cframeside=gwh cframetop=gwh cfill=gwhV;
inset mean(4.1);
run;
Occasional Contributor
Posts: 6

Re: Multiple graphs on one page

Hi and thanks so much for your reply. I ran the script as you sent but the output looks a bit funny, with the "male" data split into two sections...(please see attached). Any thoughts?
Occasional Contributor
Posts: 6

Re: Multiple graphs on one page

HI Bruno and thanks so much for the reply.  I would like to create a matrix of graphs (histograms, box plots) in one PDF page but don't have SAS/Graph (only the University Edition).  It seems pretty straightforward in R but I would like to know how to do it in SAS.

 

Thanks!

 

TIm

Solution
‎11-22-2015 04:58 PM
SAS Super FREQ
Posts: 683

Re: Multiple graphs on one page

Hi

 

You can use the ODS LAYOUT functionality to achieve what you want. The sample code below creates just a PDF file in your "MyFolder" location when using SAS University Edition. I added some comments to the code, that should get you started.

 

Attached find the PDF generated by this example code

 

Bruno

 


* close all open ODS destinations ;
ods _all_ close;

* set papersize etc. for PDF ;
options papersize="ISO A4" orientation=portrait;

* open PDF destination 
* the &_SASWS_ macro var is pointing to your "MyFolders" location
*;
ods pdf file="&_sasws_/sample.pdf";

* set size of graphics ;
ods graphics / width=8cm height=6cm;

* start gridded layout with two columns ;
ods layout gridded columns=2 ;

* generate output for first region ;
ods region;
proc sgplot data=sashelp.class;
  vbox age / group=sex;
run;

* generate output for second region;
ods region;
proc sgplot data=sashelp.class;
  histogram age;
run;

ods region;
proc sgplot data=sashelp.cars;
  vbox invoice / group=type;
run;


ods region;
proc sgplot data=sashelp.cars;
  histogram horsepower;
run;

ods layout end;

ods pdf close;
Occasional Contributor
Posts: 6

Re: Multiple graphs on one page

Forgot to mention that I did check the right hand side and couldn't find the solution I was looking for.
Thanks!
Frequent Contributor
Posts: 108

Re: Multiple graphs on one page

Move to SAS Studio , web version and free !!!
SAS Super FREQ
Posts: 683

Re: Multiple graphs on one page

Hi explorer1

 

Was the sample code provided helpful?

 

Bruno

Occasional Contributor
Posts: 6

Re: Multiple graphs on one page

Hi Bruno, thanks again, the code worked like a charm!

 

Community Manager
Posts: 552

Re: Multiple graphs on one page

Hey @explorer1, I appreciate you commenting back that @Bruno_SAS's solution worked for you! Would you take a moment and mark it as an accepted solution? That way, the answer will be more visible to other users who have the same question. Click the gear in the right corner of the answer, then select the "Accept as solution" option. Thank you!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 1220 views
  • 0 likes
  • 4 in conversation