Data files
Quick reference
To write records or fields to a data file, type:
write file_name [c(start_col, end_col)]
write may also be used to copy records to a data file. This is useful if you want to separate a particular card type from the rest of the data, or if you want to correct errors and save the corrected data in a new file for later tabulation.
To write records to a data file the command is:
write filename
to write the whole record to the named file, or
write filename c(m,n)
to write columns m to n only.
More information
If you use write in a levels job to write data to a new data file, the statement write datafile at any level will write out data for that level only. Additionally, if the write statement is inside an if clause, or a return statement is encountered, then only relevant data is written for that level. To write out data for all levels, you will need one write statement per level.
In all cases, records are written in the state they are when the write is executed, and all cards read in with the current read are copied; that is, all cards for which thisread is true. For example, if thisread1, thisread2 and thisread3 are true, Quantum writes out cards 1, 2 and 3. To prevent any of these cards being written, you can set the appropriate variable to false (zero); therefore, to print only card 1 of the three cards, write:
thisread2=0; thisread3=0
write newdat
Any number of writes to data files are allowed in the edit, and each one may write to a different file.
Records written by
write are normally as long as the record length defined with
reclen on the
struct statement. You can change this with
len= on the
filedef statement. The exception is where records end with blank columns. In this case Quantum ignores the blank columns. To create a data file of fixed length records, and your data is single coded, use the
reportn statement. If your data is multicoded you can convert it to single coded first by using the
explode statement. For more information about
explode, see
Converting multicoded data to single-coded data.
If your data is multicoded and you need to preserve the multicodes, the only way of writing out fixed length records if the data currently has trailing blank columns is to insert a dummy code in the last column of those records.
See
See also