For validation conditions, a very useful system generate variable is self. This variable denotes the value of the question being validated. Using self instead of the question's variable name in a question's validation conditions is advised because you will not have to change the variable name in the validation condition if the variable name for the question is changed.
It is important to note that using self in the enabling condition will cause an compile error.
You have a question "How many rooms does this house have?" with the variable name num_rooms. If the value 0 is not an acceptable answer for this question, then you can write either num_rooms>0 or self>0 as a validation condition for this question. The two expressions are equivalent.
This system generated variable allows you to reference specific rows within a roster. This variable can be used in enabling conditions and validations. Additionally, @rowcode can also be used to refer to certain rows in a look up table.
Assume you have roster of items and you have a question that should only be asked of two of the items (item #110 and item #114). In this case, you would use @rowcode to refer to the item number. Then you would use @rowcode and write the enabling condition to be like below:
Assume you have a roster of items that the household could have bought in the last 7 days. You want to check that the amount of money spent is not too high. Two of the items on the list are matches (item# 10) and cigarettes (item #11). Cigarettes are more expensive than matches so the largest amount that could be spent would be different for each item. Assume that you want an upper bound of 20 USD for matches and 100 USD for cigarettes. You would use @rowcode to code the upper bound specific to that item. To code this check, you would write the validation condition to be like below:
This system generated variable, @optioncode, is used to filter answer options for single select questions and multi-select questions. @optioncode refers to the numeric code for each answer option.
Assume you have a question that asks when in the past calendar year a business has been in operation. You want to filter the answer options so that only the months in the past appears. For example, if the interviewer occurs in October, you do not want the month November and December to appear because those are months in the future. Assume you have a question that captures the the date of the interview (InterviewDate). You will use date time functions to code this filter. You should write the filter to look like below:
The code InterviewDate.Value.Month takes the numeric month value from the InterviewDate variable. The filter will be evaluated for every option code and it will only display the options that it evaluate to true. In this case, months in the future will evaluate to false and will not appear as an answer option.
This system generated variable, @current, is very useful in code to filter answer options. @current refers to the current line or occurence in the roster. For example, @current refers to the current household member that you are on in the household roster.
Assume you have a question that asks the interviewer to select the ID of the spouse of the current household member. You want to filter the answer options based on the following criteria:
- Do not show the current person
- Only show household members of the opposite gender
- Only show household members 10 years old or greater
To see an example of this code in the public questionnaire, see this question.