The FILE statement enables you to direct lines that are written by a PUT statement
to an
external file.
Here is an example using the FILE statement. This example reads the data in the SAS
data set MYLIB.TEST and writes only those scores greater than 95 to the external file
C:\MYDIR\TEST.DAT:
filename test "c:\mydir\test.dat";
libname mylib "c:\mydata";
data _null_;
set mylib.test;
file test;
if score ge 95 then
put score;
run;
The previous example illustrates writing the value of only one variable of each observation
to an external file. The following example uses the _ALL_ option in the PUT statement
to copy all variables
in the current observation to the external file if the variable REGION contains the
value
west
.
libname us "c:\mydata";
data west;
set us.pop;
file "c:\sas\pop.dat";
where region="west";
put _all_;
run;
This technique of writing out entire observations is particularly useful if you need
to write variable values in a SAS data set to an external file so that you can use
your data with another application that cannot read data in a
SAS data set format.
Note: This
example uses the _ALL_ keyword in the PUT statement. This code generates
named output, which means that the variable name, an equal sign (=),
and the variable value are all written to the file. For more information
about named output, see the description of the PUT statement in SAS Statements: Reference.
The default record length
that is used by the FILE statement is 32767 characters. If the data
that you are saving contains records that are longer than 32767 characters,
you must use the FILENAME statement to define a fileref and either
use the LRECL= option in the FILENAME statement to specify the correct
logical record length or specify the LRECL= option in the FILE statement.
For details about the LRECL= option, see LRECL= in
FILE Statement: Windows .
You can also specify a different value, instead of the default 32767, for LRECL= in
an OPTIONS statement or in your
configuration file. This value stays in effect during the entire session. If you want to specify a different
LRECL= value for a specific step, then you must specify the value in a FILENAME, FILE,
or INFILE statement.