Writes the current observation to a SAS data set.
| Valid in: | DATA step |
|---|---|
| Categories: | Action |
| CAS | |
| Type: | Executable |
Table of Contents
Using OUTPUT without arguments causes the current observation to be written to all data sets that are named in the DATA statement.
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.
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. |
|---|---|
| Tips | Instead of using a data set name, you can specify the physical pathname to the file, using syntax that your operating system understands. The pathname must be enclosed in single or double quotation marks. |
| You can specify up to as many data sets in the OUTPUT statement as you specified in the DATA statement for that DATA step. |
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.
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 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. For more information, see Comparisons. 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.
These examples show how you can use an OUTPUT statement.
output;
if deptcode gt 2000 then output;
if phone=. then output markup;
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;
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.
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;
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;