BookmarkSubscribeRSS Feed
VD
Calcite | Level 5 VD
Calcite | Level 5
I want to combine boxplots on a same graph using greplay and display it in the output window.
I have been able to combine the plots in a catalog:

proc boxplot data=comp2 gout=CatComp;
plot dm1*a1;
plot dm2*a2;
plot dm3*a3;
plot dm4*a4;
run;
quit;

But have not been able to combine the plots. Any suggestions please?
Thanks.
5 REPLIES 5
Bill
Quartz | Level 8
You have the various graphs in the catalog and now you need to replay them? Take a look at http://sfew.websitetoolbox.com/post?id=2239498. The top page was produced via greplay after having produced the 6 component graphs into a catalog as you have done. The tricky part had to do with producing the individual graphs and hiding / displaying their axes depending on where they would end up on the master page..

Hope this helps to get you started,
wd
VD
Calcite | Level 5 VD
Calcite | Level 5
Bill,

Many thanks for the lead.

V
MikeZdeb
Rhodochrosite | Level 12
here's another idea if the various box plots can reasonably share a common y-axis

it rearranges data from the data set SASHELP.PRDSAL2 so you can display three
different box plots all in one PROC BOXPLOT ... three different variables used on the
the x-axis ...you have 4, a1-a4

you also have 4 different y-vars, but you can also rename dm1-dm4 to a common name
and combine the data as I do here

maybe this is 'overkill', but it does get three different variables ... or three separate boxplots ...
all into one PNG file

*
use a SASHELP data set
rearrange the data for use in PROC BOXPLOT
the PUT statements show the values to use in PROC FORMAT
;

proc sort data=sashelp.prdsal2 (keep=country actual) out=co;
by country;
run;

data co;
set co;
by country;
group + first.country;
if first.country then put country=;
run;

proc sort data=sashelp.prdsal2 (keep=prodtype actual) out=pr;
by prodtype;
run;

data pr;
set pr;
by prodtype;
group + first.prodtype;
if first.prodtype then put prodtype=;
run;

proc sort data=sashelp.prdsal2 (keep=year actual) out=yr;
by year;
run;

data yr;
set yr;
by year;
group + first.year;
if first.year then put year=;
run;

* combine all the data sets;

data all;
set co (in=c) pr(in=p) yr(in=y);
if c then name = 'Country';
else
if p then do;
group+4;
name = 'Type';
end;
else do;
group+7;
name = 'Year';
end;
run;

* specify labels for the x-axis (based on groups shown in the LOG after running data step;

proc format;
value group
1 = 'Canada'
2 = 'Mexico'
3 = 'USA'
5 = 'Furniture'
6 = 'Office'
8 = '1995'
9 = '1996'
10 = '1997'
11 = '1998'
4,7 = ' '
;
run;

* create a PNG file;

goptions reset=all ftext='calibri' htext=3 gunit=pct
dev=png xpixels=2000 ypixels=1500 gsfname=gout;

axis1 value=(a=45 h=2) label=none major=none;

* add some white space around the plot;

title1 ls=2;
title2 ls=1 a=90;
title3 ls=1 a=-90;
footnote1 ls=1;

filename gout 'z:\box.png';

proc boxplot data=all;
plot actual * group (name) / continuous boxstyle=schematic haxis=axis1;
format group group.;
run;
DanH_sas
SAS Super FREQ
If you have SAS 9.2 maintanence 3, there is an another alternative. You can use the Graph Template Language (GTL) to overlay the boxes and offset them so that they do not collide. Here's an example:

[pre]
proc template;
define statgraph boxplot;
begingraph;
layout overlay / cycleattrs=true yaxisopts=(label="Dimensions (in mm)";
boxplot x=species y=sepallength / discreteoffset=-0.2 boxwidth=0.2
name="sl" legendlabel="Sepal Length";
boxplot x=species y=sepalwidth / boxwidth=0.2
name="sw" legendlabel="Sepal Width";
boxplot x=species y=petallength / discreteoffset=0.2 boxwidth=0.2
name="pl" legendlabel="Petal Length";
discretelegend "sl" "sw" "pl";
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.iris template=boxplot; run;
[/pre]

Hope this helps!
Dan
VD
Calcite | Level 5 VD
Calcite | Level 5
Mike and Dan,
Many thanks for the detailed solutions.
Much appreciated!
V

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 2742 views
  • 0 likes
  • 4 in conversation