Data editing > Data validation > Combining testing sentences
 
Combining testing sentences
Require is often part of an if statement saying “If this is true, then that also must be true”. The previous example with r= said two things:
if the respondent didn’t try Brand A, the columns associated with it must be blank, or
if they tried Brand A, there must be a code in at least one of the associated columns.
This is more efficient than writing:
if (c125'2') r b c(126,145); else; r (c(126,145)u$ $)
which performs the same test.
Sometimes this type of test is too stringent and rejects records in which the data is correct. For example, the extra questions for people who tried the product may not contain a specific code for Refused or No Answer, so anyone who tried the product but refused to answer the extra questions would have blanks in the relevant columns. This data is correct, but would be rejected by the r= statement which expects at least one column to contain a code. Therefore, you must write a statement that checks only whether columns 126 to 145 are all blank if the respondent did not try the product; if the respondent tried the product, it does matter whether they answered the extra questions or not. The statement for this is:
if (c125'2') r b c(126,145) $Incorrect routing$
You can make this statement more powerful by writing:
if (c125'2') r b c(126,145); else; r spb c(126,145)'1/7'
This says that if the respondent did not try Brand A, all columns associated with it must be blank, but if they tried the product, you would expect those columns to be single-coded in the range ‘1/7’ or blank.
You can also make require statements apply to smaller sets of data by having records for which they would be irrelevant go around the statements. For example, there might be c112 records whether there are children in the household. If c112’1’ there are children and c113 and c114 must contain answers. You could write:
if (c112n'1') go to 30
r nb c(113,114)
30 continue
This means that all irrelevant records (respondents without children) would not be tested.
Note This system makes sense when there are several requires and you want to avoid a whole set of identical if statements. It is more efficient and it is easier to follow. Put in comments to remind yourself what you are doing and why.
See also
Data validation