Data editing > Expressions > Logical expressions > Comparing data variables and data constants > Data variables
 
Data variables
Quick reference
To test whether a data variable contains at least one of a list of codes, type:
var_name'codes'
To test whether a data variable contains none of the listed codes, type:
var_namen'codes'
To test whether a data variable contains exactly the given codes and nothing else, type:
var_name = 'codes'
To test whether a data variable contains exactly the given letter and nothing else, type:
var_name = 'letter'
To test whether two data variables contain identical codes, type:
var_name1 = var_name2
To test whether a data variable contains codes other than those listed, type:
var_nameu'codes'
To test whether two data variables do not contain identical codes, type:
var_name1uvar_name2
To check whether a column or data variable contains certain codes, place the codes, enclosed in single quotes, immediately after the name of the column or data variable. For example:
c1'1'     c156'23'    brand'5'
The expression:
Cn'p'
checks whether a column (n) contains a certain code or codes (p). The expression is true as long as column n contains at least one of the given codes. It does not matter if there are other codes present since these are ignored.
For example, to check whether column 6 contains any of the codes 1 through 4,you type:
c6'1/4'
The expression is true if c6 contains any of the codes 1, 2, 3 or 4 or any combination of those codes, regardless of what other codes may also be present. For example:
----+----1 ----+----1 ----+----1
      1 1 1
      6 2 3
      8 3 0
      - 4
      &
are true, but:
----+----1
     5
     7
     9
     -
is false.
The original example used the codes 1 through 4. You can, of course, use any codes you like and they can be entered in any order.
The opposite of cn’p’ is:
cnN'p'
which checks that a column does not contain the given code or codes. The expression is true as long as the column does not contain any of the listed codes.
For example:
c478n'5/7&'
is true as long as column 478 does not contain a 5, 6, 7 or & or any combination of them. A multicode of ‘189’ returns the logical value true, because it does not contain any of the codes ‘5/7&’ whereas a multicode of ‘1589’ makes the expression false because it contains a ‘5’.
The = operator is used to check that the contents of a column are identical to either the given codes or the given letters.
The expression:
c312='1/46'
is true as long as c312 contains all of the codes 1 through 4 and 6, and nothing else. The expression:
c142=' '
checks that column 142 is blank. The equals sign is optional when checking for blanks, so you can write:
c142' '
to check whether column 142 is blank.
The expression:
c124='A'
checks that column 124 contains the letter A and nothing else.
The = operator can also be used to compare the contents of two data variables. For example:
c56=c79
checks whether c56 contains exactly the same codes as c79. If so, the expression is true, otherwise it is false. If you have:
+----6----+ ... +----8----
1 1
5 5
the expression is true, but:
+----6----+ ... +----8----
1 1
5 5
9
yields the value false because column 79 contains a ‘9’ when column 56 does not.
If you have defined your own data variables, you could write a statement of the form:
brand1=c79
to check whether the data variable called brand1 contains the same codes as c79.
The opposite of = is U (unequal):
cnU'p'
This checks whether column n contains something other than just the code ‘p’. Suppose you have two sets of data:
----+----4 ----+----4
   1 1
   4 5
   7 9
and you write:
c34u'7'
The expression is true for both sets of data. In the first example, the ‘7’ is multicoded with a ‘1’ and a ‘4’, while in the second example, column 34 does not contain a ‘7’ at all. The only time this expression is false is when column 34 contains a ‘7’ and nothing else.
See also
Comparing data variables and data constants