Combined Program

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
proc sort data=sashelp.prdsale out=prdsale;
    by Country;
run;
options nodate nonumber;
1ods document name=work.prddocument(write);

2ods html path='your-directory-path' body='bodyPrdsale.htm'
        contents='contentsPrdsale.htm'
        frame='framePrdsale.htm'
        style=Science;

        3ods rtf file='your-file-path/RTFPrdsaleCustom.rtf' style=Science;
        4ods pdf file='your-file-path/PDFPrdsaleCustom.pdf'         
        contents=yes pdftoc=2 style=Science;
title 'Actual Product Sales';
title2 '(millions of dollars)';

proc tabulate data=prdsale 5style=[fontweight=bold];   
    class region division prodtype /6 style=[textalign=center];   
    classlev region division prodtype / 7style=[textalign=left];   
    var actual / 8style=[fontsize=3];   
    keyword all sum;
    keylabel all='Total';   
    table (region all)*(division all*10[style=[backgroundcolor=yellow]]),
          (prodtype all)*(actual*f=dollar10.) /
          style=[bordercolor=blue] box=[label='Region by Division and Type'
          11style=[fontstyle=italic]];   
run;
title;
title2;

12ods rtf exclude all;
13ods select ExtremeObs Quantiles Moments;
     
proc univariate data=prdsale;
by Country;
var actual;
run;

14ods rtf select all;
15ods 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;

16ods exclude PRINT;
17ods tagsets.excelxp file=your-file-path.'Prdsale.xls' style=Science;
18ods tagsets.excelxp select PRINT;
proc print data=sashelp.prdsale;
run;
19ods _all_ close;
20ods 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, frame, and page files. The STYLE=SCIENCE option applies the Science style to all HTML output.
3 The ODS RTF statement with the FILE= option opens the ODS RTF destination. It specifies the name and path for the RTF output file. The STYLE=SCIENCE option applies the Science style to all RTF output. The STARTPAGE=YES option specifies to put each procedure’s output on a new page.
4 The ODS PDF statement with the FILE= option opens the ODS PDF destination. It specifies the name and path for the PDF output file. The CONTENTS=YES option creates a table of contents for your PDF file. The PDFTOC=2 option specifies that the table of contents is expanded to two levels.
5 The STYLE= option specified in the PROC TABULATE statement changes all of the font to bold.
6 The STYLE= option specified in the CLASS statement centers the CLASS variable name headings.
7 The STYLE= option specified in the CLASSLEV statement left-justifies the CLASS variable level value headings.
8 The STYLE= option specified in the VAR statement changes the font size of ANALYSIS variable name headings to 3 point.
9 The STYLE= option specified in the KEYWORD statement changes the font width of KEYWORD headings to wide.
10 The first STYLE= option specified in the TABLE statement changes the background color of the cells containing the sum totals of REGION and DIVISION to yellow.
11 The second STYLE= option specified in the TABLE statement italicizes the font of the label of the empty box above the row titles.
12 The ODS RTF statement with the EXCLUDE ALL option excludes all of the output objects from the following PROC UNIVARIATE output.
13 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.
14 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.
15 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.
16 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.
17 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 a new security feature that matches the content with the extension. The STYLE=SCIENCE option applies the Science style to all TAGSETS.EXCELXP output.
18 The ODS TAGSETS.EXCELXP statement with the SELECT option selects the output object named Print.
19 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.
20 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
proc sort data=sashelp.prdsale out=prdsale;
    by Country;
run;
options nodate nonumber;
ods document name=work.prddocument(write);

ods html path='your-directory-path' body='bodyPrdsale.htm'
        contents='contentsPrdsale.htm'
        frame='framePrdsale.htm'
        style=Science;

        ods rtf file='your-file-path/RTFPrdsaleCustom.rtf' style=Science;
        ods pdf file='your-file-path/PDFPrdsaleCustom.pdf'         
        contents=yes pdftoc=2 style=Science;
title 'Actual Product Sales';
title2 '(millions of dollars)';

proc tabulate data=prdsale style=[fontweight=bold];   
    class region division prodtype / style=[textalign=center];   
    classlev region division prodtype / style=[textalign=left];   
    var actual / style=[fontsize=3];   
    keyword all sum;
    keylabel all='Total';   
    table (region all)*(division all*[style=[backgroundcolor=yellow]]),
          (prodtype all)*(actual*f=dollar10.) /
          style=[bordercolor=blue] box=[label='Region by Division and Type'
          style=[fontstyle=italic]];   
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' style=Science;
ods tagsets.excelxp select PRINT;
proc print data=sashelp.prdsale;
run;
ods _all_ close;
ods html;