<< Click to Display Table of Contents >> Navigation: Reference Manual > Definitions > Logic definitions |
IMPORTANT: we recommend you never refer to verbatim entries in logic definitions. If you use this type of filter, then it must be removed after data has been entered because you will not be able to run any analysis.
Logic definitions are used to define:
•Filters and hold filters
•Each response in a single-coded or multi-coded variable
•Base for analysis
A logic definition comprises one or more tests on an earlier entry (question, filter or variable) using logical operators (and, or) and parentheses.
Logic definitions are defined with a Logic definition user control which is described in a separate section. They can be typed as syntax, or created using menu selections with the "Tests" tab page.
TIP: in syntax, logic definitions may be typed in upper or lower case and you may leave spaces (blanks) where you like.
In a filter entry the logic definition describes those who pass the filter - those who will be asked questions where the filter is applied. In a hold filter, the logic definition describes the interviews that are faulty and should be stopped.
In a single-coded or multi-coded variable response, the logic definition describes the respondents that should have this response selected.
IMPORTANT: in a single-coded variable, only the first "true" response will be selected. Any later responses will be ignored.
In analysis the definition describes the respondents who will be included in the report.
These are special logic definitions that consist of a single letter:
•T (true) meaning everybody
•F (false) meaning nobody
•R (reject) meaning select if all other responses are false (only in a variable response definition)
The tests that can be used in logic are all similar and are as follows:
•$entry / value
•$entry / > value
•$entry / < value
•$entry / value .. value
•$entry / = [entry]
•$entry / > [entry]
•$entry / < [entry]
•$entry / N value
•$entry / N > value
•$entry / N < value
•$entry / N value..value
•$entry / N = [entry]
•$entry / N > [entry]
•$entry / N < [entry]
Where entry is the name of an earlier entry (question, filter or variable) and value is dependant on the type of entry being tested. If N is used, the test is the reverse - true if the value (or values) are NOT found in the entry.
The syntax value .. value means in the inclusive range, for example 2..4 means 2 or 3 or 4.
The [entry] references shown above compare the values of two entries. The enclosing square brackets ( [ ] ) are needed.
TIP: when typing logic definitions you do not need to include the $ sign before the entry name.
When referring to single-coded questions or single-coded variables, value can be:
•Any valid response number
•B meaning no response selected
Examples:
$Q1/5
$Q1/n4..6
$Q1/b
When referring to multi-coded questions or multi-coded variables, value can be:
•Any valid response number
•B meaning no response selected
•S meaning only one response selected (multi-coded only)
•M meaning more than one response selected (multi-coded only)
Examples:
$Q2/n5
$Q2/1..5
$Q2/nb
$Q2/ns
$Q2/m
When referring to integer, date and time entries, value can be:
•Any valid value up to 15 digits long
•U meaning "undefined" (filtered or left empty)
Examples:
$Q3/0
$Q3/-5
$Q3/>0
$Q3/n<100
$Q3/n101..999
$Q3/U
$Q4/20060101..20061231
$Q5/>1230
When referring to the serial number value can be:
•Any valid positive value up to 15 digits long
Examples:
$serial/15
$serial/>100
$serial/<100
$serial/101..999
$serial/n10001..99999
When referring to float entries, value can be:
•Any valid value including the decimal point
•U meaning "undefined" (filtered or left empty)
Examples:
$Q6/0.0
$Q6/-5.5
$Q6/>0.0
$Q6/n<100.0
$Q6/101.0..999.0
$Q6/nu
IMPORTANT: be careful when using ranges on float entries. For example, the two ranges 1.0 to 2.0,and 3.0 to 4.0, would not include any value between 2.0 and 3.0 (2.1 or 2.9).
Usually you should create an integer variable copy which will round each value to the nearest whole number and use that instead.
For a float with two decimal places, define an integer with an arithmetic definition that multiplies the float entry by 100. You can then use whole numbers to test the integer, for example 100 to 199 which would be 1.0 to 1.99 in the original float entry.
When referring to character entries, value can be:
•Any valid text surrounded by quotes
Examples:
$Q7/'Male'
$Q7/n'Female'
The case (upper or lower) of the text in quotes is important, except in a variable when you have set the option to ignore case when comparing.
If the text being checked contains an apostrophe (') you need to use two of them, for example:
$weather/'If it''s raining'
When referring to filter entries, value can be:
•1 (filter is true)
Examples:
$F1/1
$F1/n1
In variables there are three extra single character logic definitions that can be used:
•T always true (selected)
•F always false (never selected)
•R reject, used if no previous response selected (not recommended for multi-coded)
IMPORTANT: R (reject) in a multi-coded variable will also be selected (and any others deselected) if more than one response is true. For this reason we recommend adding a reject category as a definition, if necessary copying the variable to a new variable.
Any two entries that have a value can be compared:
•Single-coded. Value is the response number set or 0 if blank (empty)
•Integer
•Float
•Date. Value is YYYYMMDD
•Time. Value is HHMMSS
For the last 4 above, if blank (undefined) it will be treated as a very small number. If both entries being compared are undefined they will be treated as equal.
The entry name whose value is to be used is put in square brackets.
Examples:
$Q3/>[Q4]
$Q3/<[Q4]
$Q3/=[Q4]
$Q3/n>[Q4] equivalent to <= (less than or equal to)
$Q3/n<[Q4] equivalent to >= (greater than or equal to)
$Q3/n=[Q4] equivalent to != (not equal to)
$Q4/nu.$Q3/>[Q4]
$Q3/nu.$Q4/nu.$Q3/=[Q4]
Tests are combined using AND (.) and OR (+).
TIP: when typing syntax you can use the words AND, OR, or the symbols . (full stop), + (plus sign).
TIP: each time you specify responses to a question that are not consecutive, you must repeat the question name and forward slash (/), before referring to the responses. For example you cannot use Q3/5 OR 8.
Examples:
$Q3/0 AND $Q12/2..6
$Q3/0 . $Q12/2..6
$Q3/5 OR $Q3/8 OR $Q3/11
$Q3/5 + $Q3/8 + $Q3/11
IMPORTANT: be careful using both AND and OR without parentheses; the expression will be evaluated left to right.
You can include parentheses (round brackets) to control the order of processing. Any tests within a pair of parentheses will be evaluated first.
Parentheses can be nested to any level.
IMPORTANT: without parentheses the definition will be evaluated from left to right.
For example:
Q1/1 OR Q1/5 AND Q2/1 OR Q2/5 means ((Q1/1 OR Q1/5) AND Q2/1) OR Q2/5
Using parentheses we could alter the processing order so that the two OR combinations are done first:
(Q1/1 OR Q1/5) AND (Q2/1 OR Q2/5)