The set tag or set value widget assigns a value to a specified question or variable. It's typically used to store values for skipped questions.
1. Select any activities you have tried before.
type: checkbox
1. Running
2. Walking
3. Lifting weights
4. Biking
5. Playing sports
6. Swimming
7. Yoga
set: Q2 {value: $Q1} {condition: countChecked($Q1) == 1}
2. Select your favorite of these activities.
show if: countChecked($Q1) > 1
type: radio
optsfrom: Q1
In the example above, if only a single option is chosen at Q1, that same option will be set as the answer for Q2.
Tip! The autocode tag is a newer method for setting a value to a closed-ended question when only one option has been selected in a previous question, as illustrated in the example above.
Details
- The
settag orset valuewidget is flexible and powerful. It can be used to assign a value to any question or variable type. For assistance with complex setups, contact Support or send an email to help@intellisurvey.com. - Setting a value requires, at minimum, the question whose value is to be set, and the
valueto assign. - The
valuecan accept either a static number, such as '1', or a dynamic value, such as '$Q1'. - When setting a value to a checkbox question, use the
optiontag to specify which answer option should be coded. Not applying theoptiontag could result in overwriting existing data or recording incorrect data. - The
conditiontag can be added to apply a logical statement. If true, it triggers setting the value. Without this tag, the value is always set. - The question value can accept a question ID (e.g., 'Q2') or use Perl syntax to construct a complex ID as its input.
- Setting a value can be done in a single line as in the example above, or as a standalone widget.
Additional tags
There are a few tags that are often added to set a value.
| Tags | Description |
condition |
Evaluates a logical statement, also known as an "if statement." If the statement is true, setting the value is triggered. |
onload |
Executes setting the value when the page loads, instead of when the page is submitted. |
option |
Specifies the option ID in the question that should be automatically coded. |
Additional examples
Setting values to a checkbox question
When setting a value for a multiselect (checkbox) question, you should specify both the option ID and the value. Similar to how a checkbox question appears in an Excel export — where each option ID has its own column, and values are '1' for selected and '0' for not selected — you must follow the same pattern.
- First, specify the question ID.
- Then, identify the option ID to be coded.
- Finally, assign a value of '1' for "selected."
Not applying the option tag could result in overwriting existing data or recording incorrect data.
In the example below, each set punches a specific option at QCOLORTEMP. If the condition is met (i.e., certain colors are selected), the corresponding option at QCOLORTEMP is set to '1' (selected). This allows applicable options based on Q1 to be preselected for the respondent at QCOLORTEMP.
set list: COLORS
1. Red
2. Green
3. Blue
4. Cyan
5. Magenta
6. Yellow
7. Orange
8. Purple
9. Brown
10. Gray
11. Black
12. White
1. Which colors do you like?
type: checkbox
optsfrom: COLORS
set: QCOLORTEMP {option: 1} {value: 1} {condition: anyChecked($Q1,1,6,7,9)}
set: QCOLORTEMP {option: 2} {value: 1} {condition: anyChecked($Q1,2,3,4,5,8)}
set: QCOLORTEMP {option: 3} {value: 1} {condition: anyChecked($Q1,10,11,12)}
COLORTEMP. Which color temperatures do you like? Some options have been preselected for you based on your answers to the previous question.
type: checkbox
1. Warm
2. Cool
3. Neutral
Note: The question or variable being punched should not include a condition tag, decorator, or built-in condition (e.g., coded variables), as this will override the condition set by set value.
Coding a numeric table from a checkbox question
In the example below, if the respondent selects only one option at Q3 they skip Q4 because of the showif. We use get_first_answer to retrieve the selected option ID, which is then combined with 'Q4R' to construct the full question ID, for example 'Q4R3'. The specified row is then set to 10.
3. Thinking of your last 10 hours of exercise, which of these activities were included?
type: checkbox
1. Running
2. Walking
3. Lifting weights
4. Biking
5. Playing sports
6. Swimming
7. Yoga
set: 'Q4R' . get_first_answer('Q3') {value: 10} {condition: countChecked($Q3) == 1}
4. Approximately how many of the last 10 hours of exercise were spent on each activity?
type: number table
showif: countChecked($Q3) > 1
rowsfrom: Q3
Setting a value with a list function condition
In the example below, if the respondent selects any of the soda options 1-3 at Q1, they will have a value of '1' set for the invisible QSODA question. If the respondent does not select any of the soda options, they will have a value of '2' set for QSODA.
1. Which is you favorite type of soda?
type: checkbox
required: n
1. Cola
2. Ginger ale
3. Fruit flavored
99. I don't like soda {exclusive: y}
set: QSODA {value: 1} {condition: listCount(Q1.options -[99]; anyChecked($Q1,[id])) > 0}
set: QSODA {value: 2} {condition: listCount(Q1.options -[99]; anyChecked($Q1,[id])) < 1}
SODA. Did the repondent select any of the sodas?
type: radio
invisible: y
1. Yes
2. No
Combining two tables' data into one with a 'set value' widget
The tables are split for a better respondent experience, but the client needs a single table for analysis. A block loops through a set value widget, using the value tag to pull answers from Q7_1 or Q7_2. If a value is found, it is stored in the hidden table for that row.
set list: BRANDS
optsfrom: series[1..18]
set list: 1TO7
optsfrom: series[1..7]
7_1. Please rate each brand on a scale on 1 to 7, where 1=most likable and 7=least likable.
systemvar: y
type: radio table
headings: Most, Least
optsfrom: series[1..7]
rowsfrom: BRANDS [1..9] {text: Brand [id]}
7_2. Please rate each brand on a scale on 1 to 7, where 1=most likable and 7=least likable.
systemvar: y
type: radio table
headings: Most, Least
optsfrom: series[1..7]
rowsfrom: BRANDS [10..18] {text: Brand [id]}
block:<<BLKSV7
set value
question: Q7R%%ID%%
value: $Q7_1R%%ID%% || $Q7_2R%%ID%%
BLKSV7
list: BRANDS
7. Hidden variable that receives the combined data from the set value block, BLKSV7.
type: radio table
invisible: y
optsfrom: series[1..7]
rowsfrom: BRANDS
Tip! The newer page every tag is preferred to split tables across multiple pages.
Using 'onload' with a 'set value' widget
In the example below, the set value uses the onload tag to automatically assign the value '1' to the first row ("Self") as soon as the page loads. Without this tag, the value would only be set when the table is submitted, which wouldn't be helpful for the respondent.
set value
question: QC3R1
value: 1
onload: y
C3. Please provide how many of each of the following live in your household.
instructions: Please count yourself.
type: integer table
if blank: 0
range: 0-20
rows:
1. Self
2. Spouse/Partner
3. Children under age 18
4. Children age 18-22
5. Children age 23 or older
6. My parents or my spouse’s or partner’s parents
7. Other adults
show column total: Total number in household
validation: $QC3R1 == 1
message: Please enter '1' for Self
Comments
0 comments
Please sign in to leave a comment.