Data editing > Expressions > Logical expressions > Comparing values
 
Comparing values
Quick reference
To compare the values of two arithmetic expressions, type:
arith_exp log_operator arith_exp
where log_operator is one of the operators:
.eq.
.gt.
.ge.
.lt.
.le.
.ne.
More information
Values are compared when you need to check whether an expression has a given value; for example, did the respondent buy more than 10 pints of milk?
Values are compared by placing arithmetic expressions on either side of one of the following operators:
Operator
Description
.eq.
Equal to
.gt.
Greater than
.ge.
Greater than or equal to
.lt.
Less than
.le.
Less than or equal to
.ne.
Not equal to / unequal to
If the number of pints of milk that the respondent bought is stored in columns 114 and 115, the expression to check whether they bought more than ten pints would be:
c(114,115) .gt. 10
If the number in these columns is greater than ten the expression is true, otherwise it is false.
Basic elements shows that integer variables may take numeric values or the logical values true and false depending upon whether or not the value is zero. To check whether the respondent bought any packets of frozen vegetables, you can either write:
fveg .gt. 0
to check the numeric value of the variable fveg, or:
fveg
to check whether the logical value of fveg is true. To check whether fveg is false (that is, zero), write:
.not. fveg
For more information about .not., see Combining logical expressions.
See also
Logical expressions