Data visualization with SAS programming

Combining boxplots with greplay

Reply
Frequent Contributor
Frequent Contributor
Posts: 94

Combining boxplots with greplay

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.
Super Contributor
Posts: 291

Re: Combining boxplots with greplay

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
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Combining boxplots with greplay

Bill,

Many thanks for the lead.

V
Valued Guide
Posts: 765

Re: Combining boxplots with greplay

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;
SAS Super FREQ
Posts: 925

Re: Combining boxplots with greplay

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
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Combining boxplots with greplay

Mike and Dan,
Many thanks for the detailed solutions.
Much appreciated!
V
Ask a Question
Discussion stats
  • 5 replies
  • 919 views
  • 0 likes
  • 4 in conversation