Вы находитесь на странице: 1из 4

OUTPUT

Writes the current observation to a SAS data set


Valid: in a DATA step
Category: Action
Type: Executable
Syntax
Without Arguments
Arguments
Details
When and Where the OUTPUT Statement Writes Observations
Implicit versus Explicit Output
When Using the MODIFY Statement
Comparisons
Examples
Example 1: Sample Uses of OUTPUT
Example 2: Creating Multiple Observations from Each Line of Input
Example 3: Creating Multiple Data Sets from a Single Input File
Example 4: Creating One Observation from Several Lines of Input
See Also
Syntax
OUTPUT<data-set-name(s)>;
Without Arguments
Using OUTPUT without arguments causes the current observation to be written to all
data sets that are named in the DATA statement.
Note: If a MODIFY statement is present, OUTPUT with no arguments writes the
current observation to the end of the data set that is specified in the MODIFY
statement.
Arguments
data-set-name
specifies the name of a data set to which SAS writes the observation.
Restriction: All names specified in the OUTPUT statement must also appear in
the DATA statement.
Tip: You can specify up to as many data sets in the OUTPUT statement
as you specified in the DATA statement for that DATA step.
Details

When and Where the OUTPUT Statement Writes Observations


The OUTPUT statement tells SAS to write the current observation to a SAS data set
immediately, not at the end of the DATA step. If no data set name is specified in the
OUTPUT statement, the observation is written to the data set or data sets that are listed in
the DATA statement.
Implicit versus Explicit Output
By default, every DATA step contains an implicit OUTPUT statement at the end of each
iteration that tells SAS to write observations to the data set or data sets that are being
created. Placing an explicit OUTPUT statement in a DATA step overrides the automatic
output, and SAS adds an observation to a data set only when an explicit OUTPUT
statement is executed. Once you use an OUTPUT statement to write an observation to
any one data set, however, there is no implicit OUTPUT statement at the end of the
DATA step. In this situation, a DATA step writes an observation to a data set only when
an explicit OUTPUT executes. You can use the OUTPUT statement alone or as part of an
IF-THEN or SELECT statement or in DO-loop processing.
When Using the MODIFY Statement
When you use the MODIFY statement with the OUTPUT statement, the REMOVE and
REPLACE statements override the implicit write action at the end of each DATA step
iteration. See Comparisons for more information. If both the OUTPUT statement and a
REPLACE or REMOVE statement execute on a given observation, perform the output
action last to keep the position of the observation pointer correct.
Comparisons
• OUTPUT writes observations to a SAS data set; PUT writes variable values or
text strings to an external file or the SAS log.
• To control when an observation is written to a specified output data set, use the
OUTPUT statement. To control which variables are written to a specified output
data set, use the KEEP= or DROP= data set option in the DATA statement, or use
the KEEP or DROP statement.
• When you use the OUTPUT statement with the MODIFY statement, the
following items apply.
o Using an OUTPUT, REPLACE, or REMOVE statement overrides the
default write action at the end of a DATA step. (OUTPUT is the default
action; REPLACE becomes the default action when a MODIFY statement
is used.) If you use any of these statements in a DATA step, you must
explicitly program output for the new observations that are added to the
data set.
o The OUTPUT, REPLACE, and REMOVE statements are independent of
each other. More than one statement can apply to the same observation, as
long as the sequence is logical.
o If both an OUTPUT and a REPLACE or REMOVE statement execute on
a given observation, perform the OUTPUT action last to keep the position
of the observation pointer correct.
Examples

Example 1: Sample Uses of OUTPUT


These examples show how you can use an OUTPUT statement:
• /* writes the current observation */
• /* to a SAS data set */
• output;
• /* writes the current observation */
• /* when a condition is true */
• if deptcode gt 2000 then output;
• /* writes an observation to data */
• /* set MARKUP when the PHONE */
• /* value is missing */
• if phone=. then output markup;

Example 2: Creating Multiple Observations from Each Line of Input


You can create two or more observations from each line of input data. This SAS program
creates three observations in the data set RESPONSE for each observation in the data set
SULFA:
data response(drop=time1-time3);
set sulfa;
time=time1;
output;
time=time2;
output;
time=time3;
output;
run;

Example 3: Creating Multiple Data Sets from a Single Input File


You can create more than one SAS data set from one input file. In this example,
OUTPUT writes observations to two data sets, OZONE and OXIDES:
options yearcutoff= 1920;

data ozone oxides;


infile file-specification;
input city $ 1-15 date date9.
chemical $ 26-27 ppm 29-30;
if chemical='O3' then output ozone;
else output oxides;
run;

Example 4: Creating One Observation from Several Lines of Input


You can combine several input observations into one observation. In this example,
OUTPUT creates one observation that totals the values of DEFECTS in the first ten
observations of the input data set:
data discards;
set gadgets;
drop defects;
reps+1;
if reps=1 then total=0;
total+defects;
if reps=10 then do;
output;
stop;
end;
run;

OUTPUT Statement
OUTPUT OUT=SAS-data-set < keyword ... keyword > ;

The OUTPUT statement creates a new SAS data set containing diagnostic measures
calculated after fitting the model.

You can request a variety of diagnostic measures that are calculated for each observation
in the data set. The new data set contains the variables specified in the MODEL statement
in addition to the requested variables. If no keyword is present, the data set contains only
the predicted values.

Details on the specifications in the OUTPUT statement are as follows.


OUT=SAS-data-set
specifies the name of the new data set to contain the diagnostic measures. This
specification is required.
keyword
specifies the statistics to include in the output data set. The keywords and the statistics
they represent are as follows:
PRED
predicted values
ADIAG
diagonal element of the hat matrix associated with the observation

The names of the new variables that contain the statistics are formed by using a prefix of
one or more characters that identify the statistic, followed by an underscore (_), followed
by the dependent variable name.

For example, suppose that you have a dependent variable y, and you specify the
keywords PRED and ADIAG. In this case, the output SAS data set will contain the
variables P_y and ADIAG_y.

Вам также может понравиться