In this article
When designing a survey, the options available for you to use as the answers to your questions are limited only by your imagination. To simplify the data processing therefore, rather than using the "user-defined" question and answer texts in the database, the Survey Designer allocates a code to each question, and to each answer option for each question. The code used to identify a question is called the "Question ID" (go to Question ID for more information), and that used to identify an answer option is termed the "Code". Each Question ID MUST be unique for the survey, and each answer code for a question MUST be unique for that question.
For single questions and the items of a grid, the codes are stored in the database as string values. For multi questions the codes are used together with the Question ID as the variable name. For example a multi question q1 with three answer alternatives with the codes 1, 2 and 3 will give the three variables q1_1, q1_2 and q1_3 in the database. The same logic applies for the elements of a grid.
When creating the answers for a question, you can apply codes to the answer options manually by typing the desired codes into the fields in the Code column on the question's Answers tab. If a code is not supplied manually, then in most cases one will be allocated automatically when the question is saved. This automatic code will be equal to the answer's position in the list, starting from 1. Note that in some cases the codes will not be allocated automatically until the survey is launched. Cases where codes will NOT be allocated automatically include:
- Answer lists in the “Scales and Lists” folder because these may be used in different contexts, before or after other elements, and may also contain one or more “Scales and Lists” items.
- Answer lists that contain a reference to one or more reusable scales or lists, for the same reason as above.
- Answer lists containing a reference to a “Loop Reference” list because the content of these can be dynamic.
Note that in all these cases you can set the codes manually.
Note: When creating codes manually the ampersand character (&) must not be used as this can cause problems with scripting.
Important
If you change the answer list while a survey is running, you MUST ensure that the codes follow the original answers.
Codes can only contain alphanumeric characters, with no white space. The default maximum length is 32 characters, though you can change this by typing a value (maximum 50) into the Field Width field in the question's Properties sheet. Illegal characters will cause the database compilation to abort. A maximum of 50 characters will not be a problem for single questions, however problems will arise during launch if grid and/or multi questions use the full 50-character codes - see the note below.
Note: In the database, the column headers are constructed as a combination of the question id and the code, and are limited to 50 characters. If this limit is exceeded for a header, then an error message will be displayed when you attempt to launch the survey. Care must therefore be taken when allocating codes for grid and multi questions if the code maximum has been increased above its default setting.
Important
For a question that includes a loop reference, any non-loop reference answers must be given codes manually. These answers cannot be allocated codes automatically as the loop reference will very likely cause duplicate codes to be generated.