Data editing > Expressions > Logical expressions > Combining logical expressions > .not. with .and. and .or.
 
.not. with .and. and .or.
When you use .not. with expressions in parentheses, be very careful that what you write is what you mean. Take the conditions male and married. The condition:
(Male .and. Married)
refers only to married men. The opposite of this is:
.not. (Male .and. Married)
which refers to unmarried men and all women. This can also be written as:
.not. Male .or. .not. Married
The first .not. collects all the women, the second collects everyone who is not married (for example, single, widowed, and so on), and together they collect people who are female and unmarried. Use .or. instead of .and. here because the latter will gather unmarried women but will ignore the unmarried men and married women.
Reversing .or. expressions works in exactly the same way. The expression:
(Male .or. Married)
means anyone who is Male, or anyone who is Married, or anyone who is Male and Married. The opposite of this is:
.not. (Male .or. Married)
which means anyone who is not Male or is not Married or is not both; that is, anyone who is a woman and is unmarried. This can be written as:
.not. Male .and. .not. Married
Summary
Positive
Negative
is the same as
(A .and. B)
.not. (A .and. B)
.not. A .or. .not. B
(A .or. B)
.not. (A .or. B)
.not. A .and. .not. B
Example
Here is an example using columns and codes:
.not. (c(135,137)=$519$ .or. c160'6/0')
If the data is:
3----+----4----+----5----+----6----+
     519 1
     9 &
the expression is true because c(135,137) do not contain just the codes 5, 1 and 9 (c135 is multicoded), and c160 does not contain any of the codes 6 through 0. The expression is false only if:
column 135 contains a 5 only, column 136 contains a 6 only and column 137 contains a 9 only, and
column 160 contains any of the codes 6 through 0, either singly or as a multicode. Therefore, you could write the expression as:
.not. c(135,137)=$519$ .and. .not. c160'6/0'
See also
Combining logical expressions