Now that you have created
output for the various applications that you want to use, you can
combine the different programs into a single program. You can create
an ODS document to store your output objects. You can then replay
your output or modify your output objects without having to resubmit
any procedures.
CAUTION:
The following program
contains numbered callouts that help explain specific parts of the
program. When you copy and paste this program into a SAS code editor,
the callouts are copied as well, which results in errors. If you want
to copy and paste this program, use Combined Program without Callouts.
Combined Program with Callouts
options nodate nonumber;
proc sort data=sashelp.prdsale out=prdsale;
by Country;
run;
1ods document name=work.prddocument(write);
2ods html path='your-directory-path'
body='html-bodyPrdsale.htm'
contents='html-contentsPrdsale.htm'
frame='html-framePrdsale.htm';
3ods pdf file='your-file-path/PDFPrdsale.pdf' ;
4ods rtf file='your-file-path/RTFPrdsale.rtf' ;
title 'Actual Product Sales';
title2 '(millions of dollars)';
proc tabulate data=prdsale;
class region division prodtype;
classlev region division prodtype;
var actual;
keyword all sum;
keylabel all='Total';
table (region all)*(division all),
(prodtype all)*(actual*f=dollar10.) /
misstext=[label='Missing']
box=[label='Region by Division and Type'];
run;
title;
title2;
5ods rtf exclude all;
6ods select ExtremeObs Quantiles Moments;
proc univariate data=prdsale;
by Country;
var actual;
run;
7ods rtf select all;
8ods pdf select none;
title 'Sales Figures for First Quarter by Product';
proc sgpanel data=prdsale;
where quarter=1;
panelby product / novarname;
vbar region / response=predict;
vline region / response=actual lineattrs=GraphFit;
colaxis fitpolicy=thin;
rowaxis label='Sales';
run;
9ods exclude PRINT;
10ods tagsets.excelxp file=your-file-path.'Prdsale.xls';
11ods tagsets.excelxp select PRINT;
proc print data=sashelp.prdsale;
run;
12ods _all_ close;
13ods html;
1 |
The
ODS DOCUMENT statement creates the document Work.PrdDocument. Work.PrdDocument
stores all of the output generated between the opening ODS DOCUMENT
statement and the ODS _ALL_ CLOSE statement.
|
2 |
The
ODS HTML statement specifies the names and paths for the body, contents,
and frame files.
|
3 |
The
ODS PDF statement with the FILE= option opens the ODS PDF destination
(which is a member of the PRINTER family of destinations). It specifies
the name and path for the PDF output file.
|
4 |
The
ODS RTF statement with the FILE= option opens the ODS RTF destination.
It specifies the name and path for the RTF output file.
|
5 |
The
ODS RTF statement with the EXCLUDE ALL option excludes all of the
output objects from the following PROC UNIVARIATE output.
|
6 |
The
ODS SELECT statement specifies that the output objects ExtremeObs,
Quantiles, and Moments be sent to all open destinations that do not
specifically exclude PROC UNIVARIATE output with the EXCLUDE option,
such as the previous ODS RTF statement. The ODS statement with the
SELECT or EXCLUDE option must be specified after the opening ODS statement.
|
7 |
The
ODS RTF statement with the SELECT ALL option selects all of the output
objects from the following PROC SGPANEL output. It sends the output
objects to the ODS RTF destination. The ODS statement with the SELECT
or EXCLUDE option must be specified after the opening ODS statement.
|
8 |
The
ODS PDF statement with the SELECT NONE option selects none of the
output objects from the following PROC SGPANEL output. The ODS statement
with the SELECT or EXCLUDE option must be specified after the opening
ODS statement.
|
9 |
The
ODS EXCLUDE statement excludes the output object named Print from
all open destinations that do not specifically select the Print output
object with the SELECT option.
|
10 |
The
ODS TAGSETS.EXCELXP statement with the FILE= option opens the TAGSETS.EXCELXP
destination (which is a member of the MARKUP family of destinations).
It specifies the name and path for the XLS output file. You can use
the .XML extension instead of the EXCELXP extension. Beginning in
Excel 2007, using the XLS extension will invoke a dialog box because
of the new security feature that matches the content with the extension.
|
11 |
The
ODS TAGSETS.EXCELXP statement with the SELECT option selects the output
object named Print.
|
12 |
The
ODS _ALL_ CLOSE statement closes all of the open destinations. This
statement is useful when you have multiple destinations open at the
same time.
|
13 |
Because
the ODS _ALL_ CLOSE statement closes all open destinations, it is
a good practice to open the ODS HTML destination again at the end
of your program. If all of the destinations are closed, you get the
following warning in the SAS Log: WARNING: No output destinations
active .
|
Combined Program without Callouts
options nodate nonumber;
proc sort data=sashelp.prdsale out=prdsale;
by Country;
run;
ods document name=work.prddocument(write);
ods html path='your-directory-path'
body='html-bodyPrdsale.htm'
contents='html-contentsPrdsale.htm'
frame='html-framePrdsale.htm';
ods pdf file='your-file-path/PDFPrdsale.pdf' ;
ods rtf file='your-file-path/RTFPrdsale.rtf' ;
title 'Actual Product Sales';
title2 '(millions of dollars)';
proc tabulate data=prdsale;
class region division prodtype;
classlev region division prodtype;
var actual;
keyword all sum;
keylabel all='Total';
table (region all)*(division all),
(prodtype all)*(actual*f=dollar10.) /
misstext=[label='Missing']
box=[label='Region by Division and Type'];
run;
title;
title2;
ods rtf exclude all;
ods select ExtremeObs Quantiles Moments;
proc univariate data=prdsale;
by Country;
var actual;
run;
ods rtf select all;
ods pdf select none;
title 'Sales Figures for First Quarter by Product';
proc sgpanel data=prdsale;
where quarter=1;
panelby product / novarname;
vbar region / response=predict;
vline region / response=actual lineattrs=GraphFit;
colaxis fitpolicy=thin;
rowaxis label='Sales';
run;
ods exclude PRINT;
ods tagsets.excelxp file=your-file-path.'Prdsale.xls';
ods tagsets.excelxp select PRINT;
proc print data=sashelp.prdsale;
run;
ods _all_ close;
ods html;