Referencing Data Locations
Specific data location references are useful when:
- You don’t have a label at the specified location, i.e., it is within a question, or over multiple questions.
- You wish to use a data type not available for label references, e.g., ^^ or #.
- You wish to override the checking for the type of question being referenced.
The data location reference syntax is:
!IF [location or label datatype datacodes]
- There must be a bracket starting and ending the data location reference.
- A location specification is required.
- To specify location, you can use a question label, question number or a specific column number.
- If using a label or question number, it must be for a question prior to the current question.
- A width may be specified, preceded by a period.
- The default width is 1 for data locations, or the width of the original question if using a label or question number.
- You can also specify starting column – ending column (23 – 27).
EXAMPLE:
!IF [10.2]>9
If the number in columns 10-11 is greater than 9, the statement would be executed.
The data type is not required. It defaults to numeric data type. [5.2] and [QQ23] would look in the specified location and expect a valid number.
The possible specified data types are string ($), punch (^ or ^^) and numeric range (#). Punch and range data types require data codes.
When using a label or question number for the data location of a question, you can use a column offset.
The syntax for using a column offset is:
!IF [label +/- offset.width^punches]
EXAMPLE:
!IF [USE+2^5.0]
This example says if the data location two columns after the first column of question USE had response codes 5,6,7,8,9,0 then ask the question.
ASCII (String) Data Comparisons
String comparisons require a dollar sign ($) on the location reference, and use the string operators = (equal) and < > (not equal).
NOTE: Question labels can also use string comparisons without the required brackets, but in that case the question type must be VARIABLE or FIELD.
EXAMPLE:
!IF [33.5$] = " " !IF [OTHER.5$] = "" !IF [33-37$] =" "
The first and third examples say, IF the data in the location columns 33-37 is blank, execute the question. The second example says, IF the data location referred to by the first five columns of the question OTHER is blank, execute the question.
String comparisons are used for the exception codes in a NUMERIC question.
EXAMPLE:
!IF [FAMILY$]="DK"
ASCII (String) Lists or Range References
You can also look for string data in groups or ranges.
The syntax is:
!IF [label$"string1"-"string2","string3"]
- The number of characters in each of the strings must be less than or equal to the width of the question.
- The dollar sign ($) indicates you’re looking for string data (literals).
- The strings must be enclosed in quotes.
- If you use a range, put a dash (-) between the quoted strings, with spaces allowed.
- If using a range, the strings must be the same length. A comma separates specific items.
- An ampersand (&) may be used to continue the specification to a new line; as always, break at a logical point, use the ampersand, and continue on the next line, indenting for readability if you like.
- Letters in strings are upshifted before the comparison is done.
- You can use non-alphanumeric references in the range; Survent uses the standard ASCII code sequence to determine what will fall in the range.
EXAMPLE:
!IF [FIRST$"a"-"z"," ","."]
This example is seeing if the question labeled FIRST has characters from A to Z, a space or a period. The maximum length of any one string referenced this way is 30 characters. Also see REFERENCING QUESTION TYPES, VARIABLE Question Types for other examples of string comparisons.
Numeric Data References
Numeric data references follow the same rules as for the NUMERIC and EXPRESSION question types regardless of the question type. If there is not valid numeric data, the result will always be false. Use the X function (see USING FUNCTIONS IN CONDITION STATEMENTS) to provide a valid 0 for nonnumeric data.
EXAMPLE:
!IF X([20])<25
This dictates that if the data in location 20 for a length of 2 is less than 25, execute the question. Numeric data types use the numeric operators (>, <, =, < >, >=, <=) for comparison, and arithmetic operators (+, -, *, /) for math. Up to 4 digits of significance are read and used.
Number Lists or Range References
The syntax for a data location numeric range reference is:
!IF [location # number range1,number range2,number range n]
The location is any valid location specification (number or label). Then comes a hash mark (#), followed by a range. The two numbers in the range are separated by a dash (-).
EXAMPLE:
!IF [40.3#30-50] !IF [AGE#18-64]
The first statement says if the data in location 40 for a width of 3 has a number from 30 to 50, execute the question. The second statement says if the data in the question AGE has a number from 18 to 64, execute the question.
The range can also consist of a combination of individual numbers and ranges.
EXAMPLE:
!IF [50.2#1-10,25,30-35,99] !IF [50-51#1-10,25,30-35,99]
Both these examples say if the data field in columns 50 through 51 has a number from 1-10 or 25 or 30-35 or 99, to execute the question.