ODS OUTPUT Statement

Produces a SAS data set from an output object and manages the selection and exclusion lists for the OUTPUT destination.
Valid in: Anywhere
Category: ODS: SAS Formatted

Syntax

ODS OUTPUT action;

Actions

The following actions are available for the ODS OUTPUT statement:

CLEAR
sets the list for the OUTPUT destination to EXCLUDE ALL.
CLOSE
closes the OUTPUT destination. When an ODS destination is closed, ODS does not send output to that destination. Closing a destination frees some system resources.
SHOW
writes to the SAS log the current selection or exclusion list for the OUTPUT destination. If the list is the default list (EXCLUDE ALL), then SHOW also writes the current overall selection or exclusion list.

Required Arguments

data-set-definition
provides instructions for turning an output object into a SAS data set. ODS maintains a list of these definitions. This list is the selection list for the OUTPUT destination. For information about how ODS manages this list, see Selection and Exclusion Lists. Each data-set-definition has the following form:
output-object-specification<=data-set>
output-object-specification
has the following form:
output-object<(MATCH_ALL<=macro-var-name> PERSIST=PROC | RUN)>
output-object
identifies one or more output objects to turn into a SAS data set.
To specify an output object, you need to know which output objects your SAS program produces. The ODS TRACE statement writes to the SAS log a trace record that includes the path, the label, and other information about each output object that is produced. For more information, see the ODS TRACE statement. Output Objects can be specified as the following:
  • a full path. For example, the following is the full path of the output object:
    Univariate.City_Pop_90.TestsForLocation
  • a partial path. A partial path consists of any part of the full path that begins immediately after a period (.) and continues to the end of the full path. For example, suppose the full path is the following:
    Univariate.City_Pop_90.TestsForLocation
    Then the partial paths are as follows:
    City_Pop_90.TestsForLocation
    Tests For Location
  • a label that is enclosed in quotation marks. For example:
    "TestsForLocation"
  • a label path. For example, the label path for the output object is as follows:
    "The UNIVARIATE Procedure"."CityPop_90"."Tests For
    Location"
    Note: The trace record shows the label path only if you specify the LABEL option in the ODS TRACE statement.
  • a partial label path. A partial label path consists of any part of the label that begins immediately after a period (.) and continues to the end of the label. For example, suppose the label path is the following:
    "The UNIVARIATE Procedure"."CityPop_90"."Tests For
    Location"
    Then the partial label paths are as follows:
    >"CityPop_90"."Tests For Location"
    "Tests For Location"</
  • a mixture of labels and paths.
  • any of the partial path specifications, followed by a pound sign (#) and a number. For example, TestsForLocation#3 refers to the third output object that is named TestsForLocation.
Tip:To create multiple data sets from the same output object, list the output object as many times as you want. Each time you list the output object, specify a different data set.
MATCH_ALL=<macro-var-name>
creates a new data set for each output object. For an explanation of how ODS names these data sets, see the discussion of the option data-set.
macro-var-name
specifies the macro variable where a list of all the data sets that are created are stored. If you want to concatenate all the data sets after the PROC step, you can use the macro variable to specify all the data sets in a DATA step.
Tip:The MATCH_ALL option is not needed to merge conflicting output objects into one data set.
CAUTION:
A data set that is produced by SAS 9.1 without MATCH_ALL might not be identical to a data set that is produced by SAS 9.0 with MATCH_ALL and then concatenated in a DATA step. With SAS 9.0, merging dissimilar output objects with the MATCH_ALL option could result in missing columns or truncated variables. With SAS 9.1, these restrictions do not apply.
For more information about merging output objects, see Merging Dissimilar Output Objects into One Data Set.
PERSIST=PROC | RUN
determines when ODS closes any data sets that it is creating, and determines when ODS removes output objects from the selection list for the OUTPUT destination.
PROC
maintains the list of definitions even after the procedure ends, until you explicitly modify it. To modify the list, use ODS OUTPUT with one or more data-set-specifications. To set the list for the OUTPUT destination to EXCLUDE ALL, use the following statement:
ods output clear;
RUN
maintains the list of definitions and keeps open the data sets that it is creating even if the procedure or DATA step ends, or until you explicitly modify the list.
data-set
names the SAS output data set. You can use a one-level or two-level (with a libref) name.
If you are creating a single data set, then the ODS OUTPUT statement simply uses the name that you specify. If you are creating multiple data sets with MATCH_ALL, then the ODS OUTPUT statement appends numbers to the name. For example, if you specify test as data-set and you create three data sets, then ODS names the first data set test. The additional data sets are named test1 and test2.
Note: If you end the filename with a number, then ODS begins incrementing the name of the file with that number. For example, if you specify may5 as data-set and you create three data sets, then ODS names the first data set may5. The additional data sets are named may6 and may7.
Default:If you do not specify a data set, then ODS names the output data set DATAn, where n is the smallest integer that makes the name unique.
Tip:You can specify data set options in parentheses immediately after data-set.
NOWARN
suppresses the warning that an output object was requested but not created.
SHOW
functions just like the ODS SHOW statement except that it writes only the selection or exclusion list for the OUTPUT destination.

Details

Merging Dissimilar Output Objects into One Data Set

By default, the ODS OUTPUT statement puts all output objects that have the same output-path into one SAS data set, regardless of any conflicting variables in the output objects. Variables created by a later output object will get a value of missing in the observations created by the earlier output object. Variables created by an earlier output object that do not exist in a subsequent output object will get a value of missing in the observations added by the later output object. If a variable created by an output object has a different type than a variable with the same name created by an earlier output object, it will be added to the output data set using a new name formed by adding a numeric suffix.

Examples

Example 1: Creating a Combined Output Data Set

Features:

ODS _ALL_ CLOSE statement

ODS HTML statement options::
BODY=
CONTENTS=
FRAME=
PAGE=

ODS LISTING statement:: CLOSE

ODS OUTPUT statement

Other features:

PROC FORMAT

PROC PRINT

PROC TABULATE

KEEP= data set option

Data set: Energy

Details

This example routes two output objects that PROC TABULATE produces to both the OUTPUT destination and the HTML destination. The result is two output objects that are combined by the ODS OUTPUT statement to create an output data set formatted as HTML output by the ODS HTML statement.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See ODS HTML Statements for Running Examples in Different Operating Environments.

Program

proc format;
   value regfmt 1='Northeast'
                2='South'
                3='Midwest'
                4='West';
   value divfmt 1='New England'
                2='Middle Atlantic'
                3='Mountain'
                4='Pacific';
   value usetype 1='Residential Customers'
                 2='Business Customers';
run;
ods output Table=energyoutput(keep=region division type expenditures_sum);
ods html body='your_body_file.html'
        frame='your_frame_file.html'
     contents='your_contents_file.html'
        page='your_page_file.html';
proc tabulate data=energy format=dollar12.;
   by region;
   class division type;
   var expenditures;
   table division,
         type*expenditures;
   format region regfmt. division divfmt. type usetype.;
   title 'Energy Expenditures for Each Region';
   title2 '(millions of dollars)';
run;
ods html path='../ods'(url=none)
                  body='odsoutput-printbody.htm';
ods html body='your_body_file_2.html';
proc print data=energyoutput noobs;
   title 'Combined Output Data Set';
run;
ods _all_ close;
ods HTML;

Program Description

Format the variables Region, Division, and Type.PROC FORMAT creates formats for Region, Division, and Type.
proc format;
   value regfmt 1='Northeast'
                2='South'
                3='Midwest'
                4='West';
   value divfmt 1='New England'
                2='Middle Atlantic'
                3='Mountain'
                4='Pacific';
   value usetype 1='Residential Customers'
                 2='Business Customers';
run;
Create the SAS output data set and specify the variables that you want to be written to the output SAS data set.The ODS OUTPUT statement creates the SAS data set EnergyOutput from the output objects that PROC TABULATE produces. The name of each output object is Table. You can determine the name of the output objects by using the ODS TRACE ON statement. The KEEP= data set option limits the variables in the output data set EnergyOutput to Region, Division, and Expenditures_sum. The variable name Expenditures_sum is generated by PROC TABULATE to indicate that the sum statistic was generated for the Expenditures variable.For more information, see ODS TRACE Statement.
ods output Table=energyoutput(keep=region division type expenditures_sum);
Create HTML output.The ODS HTML statement creates the body, frame, contents, and pages files. The output from PROC TABULATE is sent to the body file. FRAME=, CONTENTS=, and PAGE= create a frame that includes a table of contents and a table of pages that link to the contents of the body file. The body file also appears in the frame.
ods html body='your_body_file.html'
        frame='your_frame_file.html'
     contents='your_contents_file.html'
        page='your_page_file.html';
Create output data sets and an HTML report.This PROC TABULATE step creates two output objects named Table, one for each BY group, and adds them to the EnergyOutput data set. Because the HTML destination is open, ODS writes the output to the body file.
proc tabulate data=energy format=dollar12.;
   by region;
   class division type;
   var expenditures;
   table division,
         type*expenditures;
   format region regfmt. division divfmt. type usetype.;
   title 'Energy Expenditures for Each Region';
   title2 '(millions of dollars)';
run;
ods html path='../ods'(url=none)
                  body='odsoutput-printbody.htm';
Close the current body file and open a new file. Create HTML output.The ODS HTML BODY= statement closes the original body file and opens a new one. The contents, page, and frame files remain open. The contents and page files will contain links to both body files. The ODS HTML statement opens the HTML destination and creates HTML output. The output from PROC TABULATE is sent to the body file. FRAME=, CONTENTS=, and PAGE= create a frame that includes a table of contents and a table of pages that link to the contents of the body file. The body file also appears in the frame.
ods html body='your_body_file_2.html';
Print the combined data set. This PROC PRINT step prints the data set EnergyOutput that contains both BY groups. The output is added to the current body file, your_body_file_2.html.
proc print data=energyoutput noobs;
   title 'Combined Output Data Set';
run;
Close all of the open destinations.The ODS _ALL_ CLOSE statement closes all open ODS output destinations. To return ODS to its default setup, the ODS HTML statement opens the HTML destination.
ods _all_ close;
ods HTML;

HTML Output

The following HTML output shows the output data set that is created by the ODS OUTPUT statement.
Combined Data Set
Combined Data Set
The following output shows the two separate BY groups that are created by the TABULATE procedure.
Output Objects Created by PROC TABULATE
Output Objects Created by PROC TABULATE

Example 2: Using Different Procedures to Create a Data Set from Similar Output Objects

Features:
ODS HTML statement options::
BODY=
CONTENTS=
FRAME=

ODS OUTPUT statement

ODS SELECT statement

Other features:

PROC GLM

PROC PRINT

PROC REG

Data set: Iron

Details

This example creates and prints a data set that is created from the parameter estimates that PROC REG and PROC GLM generate. These procedures are part of SAS/STAT software.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See ODS HTML Statements for Running Examples in Different Operating Environments.

Program

options nodate pageno=1 pagesize=60 linesize=72;
ods html body='parameter-estimates-body.htm'
        frame='parameter-estimates-frame.htm'
     contents='parameter-estimates-contents.htm';
ods select ParameterEstimates(persist);
ods output ParameterEstimates(persist=proc)=IronParameterEstimates;
proc reg data=iron;
   model loss=fe;
title 'Parameter Estimate from PROC REG';
run;
quit;
proc glm data=iron;
   model loss=fe;
title 'Parameter Estimate from PROC GLM';
run;
quit;
ods select all;
proc print data=IronParameterEstimates noobs;
title 'PROC PRINT Report of the Data set from PROC REG';
run;
ods _all_ close;
ods html;

Program Description

Set the SAS system options for the LISTING output.The NODATE option suppresses the display of the date and time in the LISTING output. The PAGENO= option specifies the starting page number. The PAGESIZE= option specifies the number of lines on an output page. The LINESIZE= option specifies the output line length.
options nodate pageno=1 pagesize=60 linesize=72;
Create HTML output.The ODS HTML statement creates the body, frame, and contents files. The FRAME= and CONTENTS= options create a frame that includes a table of contents that links to the contents of the body file. The body file also appears in the frame.
ods html body='parameter-estimates-body.htm'
        frame='parameter-estimates-frame.htm'
     contents='parameter-estimates-contents.htm';
Specify the output objects to be sent to all open ODS destinations.The ODS SELECT statement specifies that output objects named ParameterEstimates should be sent to all open ODS destinations that do not specifically exclude them. The LISTING destination is open by default, and its default list is SELECT ALL. The ODS HTML statement has opened the HTML destination, and its default list is also SELECT ALL. Thus any object that is named ParameterEstimates will go to both these destinations. The PERSIST option specifies that ParameterEstimates should remain in the overall selection list until the list is explicitly modified.
ods select ParameterEstimates(persist);
Create the IronParameterEstimates data set.The ODS OUTPUT statement opens the OUTPUT destination and creates the SAS data set IronParameterEstimates. By default, the list for the OUTPUT destination is EXCLUDE ALL. This ODS OUTPUT statement puts ParameterEstimates in the selection list for the destination. The PERSIST=PROC option specifies that ParameterEstimates should remain in the overall selection list until the procedure ends or the list is explicitly modified.
ods output ParameterEstimates(persist=proc)=IronParameterEstimates;
Create the output objects.PROC REG and PROC GLM each produce an output object named ParameterEstimates. Because the data set definition persists when the procedure ends, ODS creates an output object from each one.
proc reg data=iron;
   model loss=fe;
title 'Parameter Estimate from PROC REG';
run;
quit;
proc glm data=iron;
   model loss=fe;
title 'Parameter Estimate from PROC GLM';
run;
quit;
Enable all open destinations to receive output objects.The ODS SELECT ALL statement sets the lists for all destinations to their defaults so that ODS sends all output objects to the HTML and LISTING destinations. (Without this statement, none of the output objects from the following PROC PRINT steps would be sent to the open destinations.)
ods select all;
Print the reports.The PROC PRINT steps print the data set that ODS created from PROC REG and PROC GLM. The output from these steps goes to both the HTML and the LISTING destinations. Links to the HTML output are added to the contents file.
proc print data=IronParameterEstimates noobs;
title 'PROC PRINT Report of the Data set from PROC REG';
run;
Close the OUTPUT and HTML destinations.The ODS _ALL_ CLOSE statement closes all open destinations. The ODS HTML statement opens the HTML destination and returns ODS to its default setting.
ods _all_ close;
ods html;

HTML Output

The HTML output includes the parameter estimates from PROC REG, the parameter estimates from PROC GLM, and a report of the data set that ODS created from each set of parameter estimates.
The table of contents identifies output objects by their labels. The label for ParameterEstimates in PROC REG is Parameter Estimates. The corresponding label in PROC GLM is Solution. Notice how the column widths in the HTML output are automatically adjusted to fit the data. Compare this layout to the layout of the columns in the LISTING output.
HTML Output from the REG, GLM, and PRINT Procedures
HTML Output from the REG, GLM, and PRINT Procedures

Example 3: Creating a Data Set with and without the MATCH_ALL Option

Features:

ODS HTML statement options:: BODY=

ODS LISTING

ODS OUTPUT statement:: MATCH_ALL

ODS TRACE statement

Other features:

PROC PRINT

PROC REG

Data set: Model

Details

This example illustrates the differences in the data sets created by specifying the MATCH_ALL option and by not specifying the MATCH_ALL option. The first program creates a merged data set by specifying the MATCH_ALL option. The second program creates a merged data set without specifying the MATCH_ALL option.
The data sets that are printed are parameter estimates that PROC REG generates. The PROC REG procedure is part of SAS/STAT software.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See ODS HTML Statements for Running Examples in Different Operating Environments.

Program 1

ods output SelectionSummary(match_all=list) = summary;
title1 'Using the MATCH_ALL Option Produces Two Data Sets With Different Columns';
ods trace on;
proc reg data=model;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=forward
            sle=.5 maxstep=3;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=backward
            sls=0.05 maxstep=3;
run;
ods trace off;
title2 'The First Data Set Has the VARENTERED Column';
proc print data=summary;
run;
title1;
title2 'The Second Data Set Has the VARREMOVED Column';
proc print data=summary1;
run;
data summarym;
   set &list;
run;
title1;
title2 'The Merged Data Set Has Both Columns';
proc print data=summarym;
run;

Program Description

Prepare a SAS data set to be created.The ODS OUTPUT statement opens the OUTPUT destination. By default, the list for the OUTPUT destination is EXCLUDE ALL. This ODS OUTPUT statement puts SelectionSummary in the selection list for the destination. The MATCH_ALL option produces a SAS data set for each instance of SelectionSummary. The name of the first data set is Summary, and the name of the second data set is Summary1. ODS stores a list of these names in the macro variable list. This variable is used later in the example to combine the data sets.
ods output SelectionSummary(match_all=list) = summary;
title1 'Using the MATCH_ALL Option Produces Two Data Sets With Different Columns';
Create the output objects and view a record of them in the log.PROC REG creates the output objects. The ODS TRACE statement writes to the SAS log a record of each output object that is created. The ODS TRACE OFF statement represses the printing of the records.
ods trace on;
proc reg data=model;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=forward
            sle=.5 maxstep=3;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=backward
            sls=0.05 maxstep=3;
run;
ods trace off;
Print the reports.The PROC PRINT steps print the data sets that ODS created from PROC REG. The output from these steps is sent to the HTML destination.
title2 'The First Data Set Has the VARENTERED Column';
proc print data=summary;
run;
title1;
title2 'The Second Data Set Has the VARREMOVED Column';
proc print data=summary1;
run;
Create a data set that contains all of the data sets.The data set SummaryM combines all the data sets that were created by the ODS OUTPUT statement. The macro variable &list contains the list of data set names.
data summarym;
   set &list;
run;
Print the merged report and specify the title.The PROC PRINT step prints the merged data set created from the DATA step. The output from this step is sent to the HTML destination. The TITLE1 statement cancels the first title, and the TITLE2 statements specify a new title for the output.
title1;
title2 'The Merged Data Set Has Both Columns';
proc print data=summarym;
run;

HTML Output

The first data set created when using the MATCH_ALL option: This HTML output contains a printed report of the Summary data set created by the ODS OUTPUT statement with the MATCH_ALL option specified. It has no VARREMOVED column.
The second data set created when using the MATCH_ALL option: This HTML output contains a printed report of the Summary1 data set created by the ODS OUTPUT statement with the MATCH_ALL option specified. It has no VARENTERED column.
The merged data set created when using the MATCH_ALL option: This HTML output contains a printed report of the SummaryM data set created by the ODS OUTPUT statement with the MATCH_ALL option specified. This is the data set created from Summary and Summary1. It contains both the VARENTERED and VARREMOVED columns.
Three Data Sets Created When Using the MATCH_ALL Option
Three Data Sets Created When Using the MATCH_ALL Option

Program 2

ods output SelectionSummary=summary;
title1 'Without the MATCH_ALL Option, ODS Produces a Single Data Set With All
        Of the Columns';
ods trace on;
proc reg data=model;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=forward
            sle=.5 maxstep=3;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=backward
            sls=0.05 maxstep=3;
run;
ods trace off;
proc print data=summary;
run;

Program Description

Prepare a SAS data set to be created.The ODS OUTPUT statement opens the OUTPUT destination and creates the SAS data set Summary. Because the MATCH_ALL option is not specified, ODS creates one data set that contains all instances of the output object SelectionSummary.
ods output SelectionSummary=summary;
title1 'Without the MATCH_ALL Option, ODS Produces a Single Data Set With All
        Of the Columns';
Create the output objects and view a record of them in the log.PROC REG creates the output objects. The ODS TRACE statement writes to the SAS log a record of each output object that is created. The ODS TRACE OFF statement represses the printing of the records.
ods trace on;
proc reg data=model;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=forward
            sle=.5 maxstep=3;
  model r33=a b r4 r8 c d e r23 r24 r29/ selection=backward
            sls=0.05 maxstep=3;
run;
ods trace off;
Print the combined data set.The PROC PRINT step prints the merged data set created by ODS. The output from this step is sent to the HTML destination.
proc print data=summary;
run;

HTML Output

This HTML output contains a printed report of the Summary data set created by the ODS OUTPUT statement without the MATCH_ALL option specified. Note that to merge data sets, you do not have to specify the MATCH_ALL option.
Using the ODS OUTPUT Statement without the MATCH_ALL Option to Combine Data Sets
Using the ODS OUTPUT Statement Without the MATCH_ALL Option to Combine Data Sets