The output statement is used in the datastep to write the current values of all variables to a data set. There is an IMPLICIT output statement at the end of each datastep iteration UNLESS an output statement appears somewhere in the datastep. The two datastep programs
data first;
input x y z;
cards;
...
data second;
input x y z;
output;
cards;
....
will function in an identical manner. If output appears by
itself on a line, the data is written to the data set specified
at the start of the datastep.
data junk;
do i=1 to 20;
input x y z;
x2=x**2;
y2=y**2;
diff=z-x2-y2;
output;
end;
cards;
.....
The output statement here causes the values of the variables
i, x, y, z,
x2, y2, and diff to be written in
the data set junk for each value of i. The
data set junk will contain 20 observations. Without the output
statement, only the data read when i=20 would appear in
junk.
The output statement can be used to create several SAS data sets in a single datastep.
data junk(keep=x y z) treasure(keep=diff);
do i=1 to 20;
input x y z;
output junk;
x2=x**2;
y2=y**2;
diff=z-x2-y2;
output treasure;
end;
cards;
.......
run;
This program creates 2 datasets. Using the keep=
data set option causes Junk to contain the
variables i, x, y, and z
while Treasure contains the single variable diff.
Copyright © 1997 by Jerry Alan Veeh. All rights reserved.