Questions with integer responses
When a question requires a whole number (integer) as a response, define it in the Metadata section of the interview script:
Syntax
Qname "Text" long [[Values]];
Parameters
Qname
The question name.
Text
The question text.
Values
The numbers or range of numbers that will be accepted as valid responses. If you omit this parameter, the interviewing program will accept any whole number in the range −2,147,483,648 to +2,147,483,647.
Responses of this type are stored in the case data as 32-bit signed integers.
You can define the numbers that will be accepted as valid responses as single values, ranges of values, or a combination of single values and ranges.
A fixed range of values
When the answer may be any number within a fixed range, type:
long [Minimum..Maximum];
For example:
PartySize "The last time you ate out
how many were there in your group?" long [1..20];
Open-ended ranges
Sometimes it is convenient to define a range with a fixed minimum value but no maximum, or with a fixed maximum value but no minimum. In these cases, the interviewing program substitutes the system default for the unspecified value. You define open-ended ranges as follows:
long [Minimum..];
or:
long [..Maximum];
For example:
EatOutTimes "Roughly how many times have you eaten out this year?" long [1..];
EatInTimes "And how many times this year have you cooked for friends?" long [..99];
A list of single values or ranges
long [Value1, Value2, ... Valuen];
where Value1 to Valuen are either single whole numbers or ranges of whole numbers.
For example, respondents may answer the following question with any of the values 4, 7, 10, 11, 12, 13, or 14:
NumberOfDays "How many days would you like the documents for?" long [4,7,10..14];
Exclusive values
Sometimes the easiest way to define valid responses is to allow all numbers in a given range but with some exceptions. These exceptions may be single values or ranges of values. To write this type of specification, define the full range first and then follow it with the values or ranges you want to exclude, with each one preceded by a ^ symbol:
long [Range, ^Exclude1, ... ^Excluden];
In the following example any number between 100 and 130 is valid except 109 to 115 inclusive and 126:
DocCode "Please enter the numeric code for the documents you would like to borrow."
long [100..130,^109..115,^126];
Stepped values
Occasionally you may have a range in which the numbers increment be a common value other than 1. Rather than listing all values separately, you can specify the lowest and highest values in the range and an incremental value that will be used to determine which other values will be considered part of the range. To specify this type of range, type:
long [Minimum..Maximum step Increment];
For example, a survey related to usage of national census returns may ask:
CensusOnline "Which year's census returns would you most like to have available online?"
long [1841..1901 step 10];
This assumes that national censuses occurred every ten years between 1841 and 1901 inclusive.
Allowing a thousands separator character
The interviewing program does not normally accept a thousands separator character in large numbers. For example, in countries that use a comma as the thousands separator, the number 1,500 will be rejected even if it is within the range specified for the question. If you want the interviewing program to accept thousands separators in numeric responses, place the following statement in the routing section of the questionnaire before the question is asked:
Qname.Validation.Options["AllowThousandsSeparator"] = True
where Qname is the name of a question with a numeric response.
The character that the interviewing program accepts as the thousands separator depends on the language or locale set for the interview. The language can be set in the script itself, otherwise it defaults to the language set in the respondent’s browser. This can be overridden by setting the interview’s locale in the script. The Locale property defines the language to be used for data input and output and for validation. For example, if the interview language is set to French, the interviewing program expects respondents to use a space as the thousands separator and a comma as the decimal point. If the script sets the locale to English, the interviewing program will then expect a comma for the thousands separator and a dot for the decimal point.
The Locale property normally mirrors the Language property so that when the language changes so does the locale. However, if you specify the locale manually this breaks the link between the two properties and any subsequent language changes do not affect the locale setting. For more information, see
Using locale to control decimal number and date formats.
Note AllowThousandsSeparator is provided primarily to maintain backwards compatibility with early versions of the interview scripting language, in which the default was to require the use of thousands separator characters.
Number of digits to write
To specify the maximum number of digits that can be written, append the precision keyword to the standard question definition:
Qname "Text" double [[Values]] precision(NumDigits);
where NumDigits is the maximum number of digits.
See also