Multi page Plots - RhoInc/sas-sgplot GitHub Wiki
Contents
- Setup
- Prep for Macro Looping
- Produce Individual Pages
- Combine Pages
Producing multi-page plots with RhoTables is a bit tedious. First we must produce each page as a standalone RT4 output. We then combine the standalone outputs into one large RT4 output.
Setup
We begin by defining some macro variables and creating a dataset, just to keep things simple below.
%let pgmdir = H:\D2G\OutputCapture;
%let tbl = FIG_TAW;
proc sort data=sashelp.cars out=cars;
by cylinders;
where n(cylinders);
run;
Prep for Macro Looping
We are going to produce a set of scatter plots of enginesize
by horsepower
with one plot/page per origin
(USA, Europe, Asia). We begin by creating a suite of macro variables corresponding to each value of origin
. PROC SQL is quite handy for this purpose.
proc sql noprint;
select distinct origin
into :origin1-
from cars
;
quit;
%let origin_n = &sqlobs;
The macro variable origin_n
tells us how many origin
values there were. The macro variables origin1
, origin2
, and origin3
contain the actual values.
Produce Individual Pages
Next we use a macro loop to cycle over the origins. Within the macro loop we first create one plain RTF file per page.
ods graphics / reset=all;
options
nodate
nonumber
orientation=landscape
;
ods graphics /
outputfmt=png
height=4in
width=8in
noborder
;
%macro pages();
%do i = 1 %to &origin_n;
*---------- capture plot in preliminary RTF file ----------;
ods results off;
ods listing close;
ods rtf file="&pgmdir\&tbl._Page&i._pre.rtf";
proc sgplot data=cars;
scatter y=enginesize x=horsepower;
where origin = "&&origin&i";
run;
ods rtf close;
ods listing;
ods results on;
%end;
%mend pages;
%pages();
This macro loop will yield three separate RT4 outputs: FIG_TAW_Page1_pre.rtf, FIG_TAW_Page2_pre.rtf, and FIG_TAW_Page3_pre.rtf.
Combine Pages
Our last step is to combine these parts into one item. First we create one column definition per page. Then we use use the WrapAtCol=
option. Note that the macro loop for WrapAtCol=
starts at 2.
%macro wrapatcol();
data dummy;
x = " ";
run;
%do i = 1 %to &origin_n;
%let Def&i = COL|&i|C|%rt4pic(&pgmdir\&tbl._Page&i._pre.rtf)|wid(126);
%end;
%RhoTables4
(ItemName=&tbl
,ItemType=figure
,Style=Table
,LineSize=126
,PageSize=52
,Data=dummy
,WrapAtCol=%do i = 2 %to &origin_n; &i %end;
);
%mend wrapatcol;
%wrapatcol();
Documentation: Assuming you are connected to the Rho network, the RhoTables4 documentation can be found here.