Ahah, almost all working now!
🙂
I wouldn't call this easy or intuitive or obvious, but at least it is there. It looks like mastering proc template and proc document to make best use of ODS would be a full time job. Thanks all for all the information and tips so far.
Here is the final code of the mockup fyi.
The charts seem not only to ignore the ToC labels, but also the page breaks in 9.1.3 (plus they are not centered, but I guess they were never told to be). Is it possible to change report justification with proc document?
Is it the same in 9.2 Cynthia?
[pre]
*** 1) Make ODS Document;
title;
footnote;
options nodate nonumber center;
ods listing close;
proc sort data=SASHELP.PRDSALE out=PRDSALE;
by COUNTRY;
run;
proc sql noprint;
select unique COUNTRY into :countries separated by '|'
from PRDSALE
order by COUNTRY;
quit;
ods document name=WORK.PRDDOC(write);
proc tabulate data=PRDSALE;
by COUNTRY;
var PREDICT;
class PRODTYPE;
table PRODTYPE all,
PREDICT*(min mean max);
run;
/* ods select Gchart;
goption dev=actximg xpixels=1000 ypixels=500;
proc gchart data=PRDSALE;
by COUNTRY;
vbar PRODTYPE/sumvar=ACTUAL des='';
run;
quit;*/
ods select ExtremeObs;
proc univariate data=prdsale;
by Country;
var actual;
run;
ods document close;
** fetch ODS document object names and arrange report order;
ods listing;
proc document name=WORK.PRDDOC;
ods output properties=PROPERTIES;
list/levels=all;
run;
ods output close;
quit;
proc sql;
create table REPORTS as
select *
,scan(PATH, 2,'\') as BYGROUP
,monotonic() as REPORT_ORDER
,min(calculated REPORT_ORDER) = calculated REPORT_ORDER as PAGE_BREAK
from PROPERTIES
where TYPE ne 'Dir'
group by BYGROUP
order by BYGROUP, REPORT_ORDER;
quit;
** create a new ODS document with 1 high level node and many children;
proc document name=WORK.NEWORDER(write);
make ONETOP;
run;
dir ^^;
dir ONETOP;
dir;
%macro loop_entries;
%local dsid rc ;
%let dsid=%sysfunc(open(REPORTS));
%let rc=%sysfunc(fetch(&dsid));
%do %while (&rc=0);
copy \work.prddoc%sysfunc(getvarc(&dsid,1)) to ^;
%let rc=%sysfunc(fetch(&dsid));
%end;
%let rc=%sysfunc(close(&dsid));
%mend;
%loop_entries
run;
quit;
** fetch new ODS document object names and add page break information;
proc document name=WORK.NEWORDER;
ods output properties=PROPERTIES2;
list/levels=all;
run;
ods output close;
quit;
data PROPERTIES2;
if _N_=1 then do;
set PROPERTIES2;
output;
end;
merge PROPERTIES2(firstobs=2)
REPORTS(keep=PAGE_BREAK);
output;
run;
** use new object names to set labels and page breaks;
ods listing;
proc document name=work.neworder(update); option mprint;
dir ^^;
dir ONETOP;
setlabel \ONETOP#1 'Top Level Node';
%macro loop_entries;
%local dsid rc country path report pb;
%let dsid=%sysfunc(open(PROPERTIES2(where=(TYPE ne 'Dir'))));
%let rc=%sysfunc(fetch(&dsid));
%do %while (&rc=0);
%let path=%sysfunc(getvarc(&dsid,1));
%let country=%substr(&path,%length(&path),1);
%let report=%substr(&path,11,%length(&path)-12);
setlabel &path "&report for %scan(&countries,&country,|)";
%let pb=%sysfunc(getvarn(&dsid,3));
%if &pb=0 %then
obpage &path /delete;;
%let rc=%sysfunc(fetch(&dsid));
%end;
%let rc=%sysfunc(close(&dsid));
%mend;
%loop_entries
run;
quit;
** 5) Now replay the new document to ODS PDF;
ods listing close;
ods pdf file='c:\temp\replay_neworder.pdf';
ods escapechar='^';
footnote "Page ^{thispage} of ^{lastpage}";
proc document name=work.neworder;
replay;
run;
quit;
ods _all_ close;
Message was edited by: Chris@NewZealand
Add question: Is it possible to change report justification with proc document?