Overview (WRITE command)
WRITE writes files
in a machine-readable format that can be used by other software applications.
When used for this purpose, the OUTFILE subcommand
is required. If OUTFILE is not specified,
the output from WRITE that can be displayed
is included with the output from your session in a format similar to that
used by the PRINT command.
Options
Formats. You can specify formats for the variables.
Strings. You can include strings within the variable specifications. The strings can be used to label values or to add extra space between values.
Multiple Lines per Case. You can write variables
on more than one line for each case. See the RECORDS subcommand.
Output File. You
can direct the output to a specified file using the OUTFILE subcommand.
Summary Table. You
can display a table that summarizes the variable formats with the TABLE subcommand.
Subcommand Order
Subcommands can be specified in any order. However, all subcommands must be used before the slash that precedes the first variable list.
Basic Specification
The basic specification is a slash followed by a variable list. The values for all of the variables specified on the list are included with the rest of the output from your session.
Syntax Rules
- A slash must precede the variable specifications. The first
slash begins the definition of the first (and possibly only) line per case
of the
WRITEoutput. - Specified variables must already exist, but they can be numeric, string, scratch, temporary, or system variables. Subscripted variable names, such as X(1) for the first element in vector X cannot be used.
- Keyword
ALLcan be used to write the values of all user-defined variables in the active dataset.
Operations
-
WRITEis executed once for each case constructed from the data file. - Values are written to the file as the data are read.
-
WRITEis a transformation and will not be executed unless it is followed by a procedure or theEXECUTEcommand. - When writing to an external file with the
OUTFILEsubcommand, line/record width can be up to 2.1 billion bytes. When writing to the Viewer, however (when there is noOUTFILEsubcommand), if a line width exceeds the line width defined bySET WIDTH, an error results and theWRITEcommand is not executed. The maximum line width you can specify withSET WIDTHis 255 bytes. - There are no carriage
control characters in the output file generated by
WRITE. - User-missing values are written just like valid values. System-missing values are represented by blanks.
- If you are writing a file to be used on another system, you should take into account that some data types cannot be read by all computers.
- If long records are less convenient than short records with multiple records per case, you can write out a case identifier and insert a string as a record identification number. The receiving system can then check for missing record numbers (see Strings for an example) .