Data editing > Data validation > Column and code validation > Automatic error correction
 
Automatic error correction
Quick reference
To define a correction code to be used as a replacement for codes which fail the required condition, type:
r [/err_code/] condition col1'codes1' :'new_code'
new_code is the code or codes to be inserted in col1 if it fails the test condition. Any codes already in that column are overwritten.
More information
Records found to have errors are printed, coded and/or rejected according to the error action code. When the run is finished, you look at these records and, if possible, correct the errors by using the on-line edit or correction file facilities: see Data correction.
You might know in advance what to do with certain types of error; say, for example, the respondent’s sex has been miscoded. You might decide or be told to recode this person as a ‘3’ in the appropriate column indicating that the sex was not known. The way to do all this in one go is to write the normal require statement that checks columns and codes, and to follow the code specification with a colon (:) and the replacement code (in this case ‘3’) enclosed in single quotes, thus:
r /2/ sp c106'12' :'3'
Any record in which c106 is not single-coded with either a ‘1’ or a ‘2’ will have the contents of c106 overwritten with a ‘3’.
The equivalent using if and an assignment statement would be written:
if (numb(c106'12').ne.1) c106'3';
+write $c106 incorrect$
Once again, the require is shorter and quicker.
When working with fields, it is not possible to define replacement strings for the field as a whole. Note that if a single replacement code is given for a field of columns, any incorrect columns in that field will be overwritten with the replacement code. The correct columns remain untouched.
If you have:
+----4----+
  1927
and you write c(237,240)'1/5' :'&'", you will have:
+----4----+
  1&2&
Note If you use this facility, remember that the replacement code is an alteration to the data, and as such is operative only as long as each record is in the C array. If you want to save these modifications you must include a statement in your edit which will write records to another file. Statements which write out new data files are split and write. Alternatively, you can use one of the action codes which writes records to the output data file.
For information about split, see Creating clean and dirty data files.
For information about write, see Print files.
See also
Column and code validation