Referencing Question Types
The syntax for IF statement references varies depending on the type of question you are referencing.
FIELD Question Type
The syntax for FIELD question response list references is:
!IF LABEL(response code1,response code 2,etc.) !IF LABEL(<>response code 1,response code 2,etc.)
- Following the IF is a space, then the label of the question that the condition is based on.
- Enclosed in parentheses, and separated by commas, a period, or a dash, are the specific responses that trigger the condition.
- Commas separate specific codes (1,2,3), while a period or a dash indicate a range (all codes, from response code 1 to n; i.e., 1-5).
- You can use any of these to specify the responses:
- code
- code,code
- code-code
- code.code
- You can combine separate codes and ranges (1-5,8). “< >” at the beginning of the response list means not these responses.
- You may use the “^” placeholder in codes that are different lengths, eg. (Yes,No^).
EXAMPLE:
!IF BRAND(1) !IF BRAND(1,2,3) !IF BRAND(1-3) !IF BRAND(1.3)
For this example, a response to the FIELD question BRAND of 1, 2, or 3 would trigger the condition and cause the question or statement to be executed.
EXAMPLE:
!IF BRAND(<>1-3)
The example above shows the use of the not equal to (< >) operator in a response list. It says, If FIELD question BRAND is not a 1 through 3, execute the question.
NOTE: When using the period or dash to indicate a range, be aware that 1.4 or 1-4 only means 1,2,3,4 if those response codes were in that order in the original response list. If the response list was in the order 1,5,4,3,2 then 1.4 means 1,5,4.
Use the XF(NUMBER_OF_RESPONSES()) function to count the responses to a multiple response FIELD question.
EXAMPLE:
!IF XF(NUMBER_OF_RESPONSES(BRAND))>=2
In the above example the question will be asked if the number of responses to the question BRAND is greater than or equal to 2.
NUMERIC and EXPRESSION Question Types
For NUMERIC questions or EXPRESSION statements or other numeric data, the syntax is:
!IF label or constant operator label or constant
For numeric data, you may use labels or constants or data locations. (See REFERENCING DATA LOCATIONS for more information). All labels must contain valid numeric data or the condition will be considered false. Following the label is a relational operator and then a number or another label.
The operators are:
= equal to <> not equal to > greater than < less than >= greater than or equal to <= less than or equal to
EXAMPLE:
!IF AGE>=21
A response to question AGE that is greater than or equal to 21 would cause the question or statement to be executed. To treat blank or non-numeric responses as if they were zero, use the X function. This is important because it allows the condition to be checked if one of the elements is missing.
EXAMPLE:
!IF X(FEB)< X(JAN)
In this example, the question would execute if the response to FEB was less than the response to JAN. Without the X function, if one of the questions did not have a numeric response, the condition would not be considered true.
See REFERENCING DATA LOCATIONS, ASCII Data Comparisons, on how to refer to the NUMERIC exception codes.
You may also look for numeric data in groups or ranges.
The syntax is:
!IF [label#num1-num2,num3]
EXAMPLE:
!IF [Q3#1-100,150]
VARIABLE Question Type
For VARIABLE length, single response field (FIELD) questions, or NUMERIC with string data, the syntax is:
!IF [label$ or "text"] operator [label$ or "text"]
NOTE: The label is followed by a dollar sign ($). This tells the program that it is doing a string (or literal) comparison. The operator can be any of those listed under NUMERIC AND EXPRESSION QUESTION TYPES.
The text or label to compare to follows. Text must be enclosed in quotes. If the specified text or the response to the second label$ matches the response, the condition will be true.
EXAMPLE:
!IF OTHER$ <> " "
In this example, the question would execute if the question OTHER was not blank.
EXAMPLE:
!IF LIKEIT$ = "yes"
This would execute the question if the answer to question LIKEIT was equal to yes. The comparison is not case sensitive — uppercase and lowercase text match — and leading blanks in string comparisons are ignored.
The program only checks as many characters as you specify. For example, if you specify “BUD”, the program will check only the first three letters. Consequently, any word or phrase starting with BUD would match, such as: BUDDHA or BUDGET. You could specify “BUD ” to not match the other words (note the space after the ‘D’).
The <,<=, >, or >= operators use the ASCII code sequence to determine the relationship. All letters are upshifted before the comparison is made.
TEXT Question Type
TEXT questions, with text type data, cannot be referenced directly. This is because the responses to TEXT questions are extremely variable. Instead, you can use the CHECKTEXT function to count the number of characters responded or whether the question was asked.
EXAMPLE:
!IF CHECKTEXT(OTHER) > 1
If the number of characters entered for TEXT question OTHER was greater than one, the current question will be executed. See USING FUNCTIONS IN CONDITION STATEMENTS for more information on the CHECKTEXT function. If you want to check the characters in the TEXT question, use a GENERATE,COPY_DATA to move the TEXT data to a VARIABLE question, then use that for the conditional checking.