BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Rhodochrosite | Level 12
Hello Experts,
 
I would like to plot multiple pairs of box plots, all next to each other, for example,  6 in one page. I’m wondering if it is possible.
Actually, I use PROC SGPLOT with pdf ods and I have one page for box plot. 
 
Thank you for your help.
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Since you output to a PDF, you can set some options like papersize and margins. You could use a A3 papersize, so there is more space for the graph, but still print it as A4. I would set the height and width using mm, as you can measure on the paper with a ruler. ODS LAYOUT has support for COLUMN_GUTTER=dimension and ROW_GUTTER=dimension

 

Here is a sample to test things out. I used macros for some of the options to make it easier to change

ods _all_ close;
options
  papersize="A3"
  topmargin=1cm
  bottommargin=1cm
  leftmargin=1cm
  rightmargin=1cm
  orientation=landscape
  nodate nonumber;
;
ods graphics / reset=all width=90mm height=135mm outputfmt=png;
ods pdf file="%sysfunc(pathname(work))/layout_gridded.pdf";
ods layout gridded columns=4 column_gutter=0;

%macro dataLabel;
  datalabel=model 
    labelfar
%mend;

%macro displayStats;
  displaystats=(n mean median max datamax min datamin  iqr range std q1 q3)
%mend;

%macro datalabelAttrs;
  datalabelattrs=(size=6pt color=blue Style=Normal Weight=Normal) boxwidth=1
%mend;

ods region;

  proc sgplot data=sashelp.cars;
    vbox invoice /
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods region;

  proc sgplot data=sashelp.cars;
    vbox horsepower/
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods region;

  proc sgplot data=sashelp.cars;
    vbox mpg_city/
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods region;

  proc sgplot data=sashelp.cars;
    vbox mpg_highway/
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods layout end;
ods pdf close;

The PDF produced is attached.

 

View solution in original post

22 REPLIES 22
Ksharp
Super User
or using GTL language.
Check PROC TEMPLATE.
BrunoMueller
SAS Super FREQ

How about using ODS LAYOUT, see sample below.

ods _all_ close;

ods graphics / width=80mm height=80mm outputfmt=static;
ods pdf file="c:\temp\layout_gridded.pdf";

ods layout gridded columns=2;

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

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

ods region;
proc sgplot data=sashelp.cars;
vbox mpg_city;
run;

ods region;
proc sgplot data=sashelp.cars;
vbox mpg_highway;
run;

ods layout end;
ods pdf close;
SASdevAnneMarie
Rhodochrosite | Level 12
Thank you, Bruno!
Unfortunately, when I add the statistics : datalabel=model displaystats=(n mean median max datamax min datamin iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1 the box plots become small.
SASdevAnneMarie
Rhodochrosite | Level 12

I use startpage=no but I still have the multiple pages :

options  device=SASPRTC nodate nonumber orientation=portrait ;

ods pdf style=Sapphire startpage=no;

	proc sgplot data=bdd;
		vbox NBMEN20/datalabel=LIBGEO  displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
		yaxis label="Nombre de ménages";
	run;
    proc sgplot data=bdd_
		vbox NBPERSC2/datalabel=LIBGEO  displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
		yaxis label="Nombre de personnes";
	run;
  proc sgplot data=bdd;
		vbox MED0 /datalabel=LIBGEO  displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
		yaxis label="Médiane";
	run;

	footnote j=left "Source de données : xxx  " ;
footnote;
ods pdf close;
sbxkoenk
SAS Super FREQ

I would use PROC SGPANEL with a panelby statement and a vbox statement.

Sample 69825: Using the SGPANEL procedure to create panels of box plots with marker symbols

https://support.sas.com/kb/69/825.html

 

Ciao,

Koen

Ksharp
Super User

I used    's code and got this :

ods graphics / width=150px height=150px outputfmt=static;
ods pdf file="c:\temp\layout_gridded.pdf";

ods layout gridded columns=4 ;

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

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

ods region;
proc sgplot data=sashelp.cars;
vbox mpg_city;
run;

ods region;
proc sgplot data=sashelp.cars;
vbox mpg_highway;
run;

ods layout end;
ods pdf close;
 

屏幕截图 2025-09-09 175027.png

SASdevAnneMarie
Rhodochrosite | Level 12

Thank you, unfortunately this code does not work when I add the statistics :


ods graphics / width=150px height=150px outputfmt=static;
ods pdf file="xxx\layout_gridded.pdf";
options  device=SASPRTC nodate nonumber  ;
ods layout gridded columns=4 ;

ods region;
proc sgplot data=sashelp.cars;
vbox invoice/datalabel=model displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
run;

ods region;
proc sgplot data=sashelp.cars;
vbox horsepower/datalabel=model  displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
run;

ods region;
proc sgplot data=sashelp.cars;
vbox mpg_city/datalabel=model   displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
run;

ods region;
proc sgplot data=sashelp.cars;
vbox mpg_highway/datalabel=model   displaystats=(n mean median max datamax min datamin  iqr range std q1 q3) datalabelattrs=(size=10pt Family="Arial" color=blue Style=Normal Weight=Normal) boxwidth=1;
run;

ods layout end;
ods pdf close;
 

Capture d’écran 2026-02-26 113335.png

BrunoMueller
SAS Super FREQ

Since you output to a PDF, you can set some options like papersize and margins. You could use a A3 papersize, so there is more space for the graph, but still print it as A4. I would set the height and width using mm, as you can measure on the paper with a ruler. ODS LAYOUT has support for COLUMN_GUTTER=dimension and ROW_GUTTER=dimension

 

Here is a sample to test things out. I used macros for some of the options to make it easier to change

ods _all_ close;
options
  papersize="A3"
  topmargin=1cm
  bottommargin=1cm
  leftmargin=1cm
  rightmargin=1cm
  orientation=landscape
  nodate nonumber;
;
ods graphics / reset=all width=90mm height=135mm outputfmt=png;
ods pdf file="%sysfunc(pathname(work))/layout_gridded.pdf";
ods layout gridded columns=4 column_gutter=0;

%macro dataLabel;
  datalabel=model 
    labelfar
%mend;

%macro displayStats;
  displaystats=(n mean median max datamax min datamin  iqr range std q1 q3)
%mend;

%macro datalabelAttrs;
  datalabelattrs=(size=6pt color=blue Style=Normal Weight=Normal) boxwidth=1
%mend;

ods region;

  proc sgplot data=sashelp.cars;
    vbox invoice /
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods region;

  proc sgplot data=sashelp.cars;
    vbox horsepower/
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods region;

  proc sgplot data=sashelp.cars;
    vbox mpg_city/
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods region;

  proc sgplot data=sashelp.cars;
    vbox mpg_highway/
      %dataLabel
      %displayStats
      %dataLabelAttrs
    ;
  run;

ods layout end;
ods pdf close;

The PDF produced is attached.

 

SASdevAnneMarie
Rhodochrosite | Level 12
Thank you, Bruno!
How to define 2 rows please if I want to have 8 box-plots?
BrunoMueller
SAS Super FREQ
As long as two rows of images will fit on the page you just continue with

ods region;
proc sgplot ...;

for the next 4 plots.
SASdevAnneMarie
Rhodochrosite | Level 12
When I add a footnote, I get the footnote for both the graphics and at the bottom of the page. How can I have the footnote only at the bottom of the page?
Ksharp
Super User

You could use NOGFOOTNOTE to get this.

ods pdf file="c:\temp\layout_gridded.pdf" nogfootnote;
SASdevAnneMarie
Rhodochrosite | Level 12
Thank you, but when I add nogfootnote I do not have the footnote.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 22 replies
  • 1750 views
  • 10 likes
  • 4 in conversation