Submit a ticket My Tickets
Welcome
Login

Question Syntax: a guide to Survey Builder's syntax

Question:

A question is made up of a container and at least 1 question.

 

Each container can have multiple questions, referred to as sub-questions.  Note that there can only ever be one answer list, but the question types can change.

e.g. you can have a shared brand list and have a multi, single or even grid question; all would be shown on the same page as 1 question.

 

Question Syntax:

The difference between addresses and logical expressions

The Walr Platform uses two different concepts in scripting: Addresses and logical expressions

 

Addresses are generally used in one of the following scenarios:

In questionnaire design it is used to determine valid answers (masking / range control)

In analysis it is used to decide what part of the data set is to be analyzed (graphics, tables)

 

Logical expressions are generally used in one of the following scenarios:

In questionnaire design: Determine who will/will not receive a question. (Filter commands / “goto” expressions)

In analysis it is used to define local or global filters (universe) in tables, graphs and other analysis.

Addresses and logical expressions can be used together. Conditions for which answers are available are based on previously answered questions (conditional range control).

 

Filters and addresses are also uses extensively in data management tools and this enables you to create cleaning statements, filter data sets, create analysis weights and create hierarchical data sets using the split tool.

 

Addresses: Syntax

An address describes an area that can contain one or more of the listed elements.  An address is characterized by the following:

The “backslash” \ is always the first character of the question address.

Answer codes are contained within “hard brackets” = [   ].

A basic logical expression always includes an address that may be any of these:

 

\Q - question

\Q.S - question.sub question

\Q.R - question.row

\Q.S.R - question.sub question.row

 

Examples of Addresses

Addresses

Description

\Q1

Entire question 1

\Q1.b

Entire sub question b of question 1

\Q1.a.c

Entire sub questions a and c from question 1

 

 

 


 

 

Addresses: Special Characters

Each of the address components Q, S, and R can include some of the following special characters:


Description

Special Characters

\

Start of new address

.

Separator for question, sub question and row

[  ]

Description of codes or frequency distribution of numeric values

:

Combine elements, from → to (continuous interval)

;

Include elements (separately, discontinuous interval)

,

Include (add) an additional element

,,

Include (add) a series of elements, from → to (continuous interval)

#

Number of repetitions

!

Not (negation)

 


 

 

Logical Expressions: Syntax

Logical expressions are "value lists" that always begin with an address and end with a desired value for that address. Logical expressions are characterized by the following:

 

Always begins with a “backslash” \.

After the “backslash”, there must always be an address that describes an element or combination of elements.

After the address comes the equal sign =.

After the equals sign comes the value list.

 

For example:

\1=1:3 when used in a filter, means question will be asked only if responses were made to the first three answers in question 1.

 

Examples of Logical Expressions

Logical Expressions

Description

\Q1=1

Answer 1 of question 1

\Q2=15:29

The value of question 2 between the values of 15-29 inclusive (only for quantitative questions)

\Q3=2;4

Include only answers 2 and 4 of question 3

\Q3.a=1;3;5:50

Include only answers 1, 3 and any value between 5 and 50.

!\Q6.a=1

Not answer 1 of sub question a of question 6.

\Q8.c.1:8=0:44

Any of answers 1 through 8 of question 8.c that are in the range of 0 through 44 inclusive (only for quantitative questions)

\Q10.a;b=1

Has selected answer 1 in either sub question a or b of question 10.

 


 

 

Logical Expressions: Special Characters

Logical Expressions: Special Characters

Description

\

Start of new expression

.

Separator for question, sub question and row

:

Combine elements, from → to

;

Include elements (separately)

#

Number of repetitions

=

Separates the address and the value list.

 

Combination of Advanced Logical Expressions (logical operators)

! - NOT

| - OR (pipe)

& - AND

( ) - Group complex expressions

 

Special Characters Used in Filters and Range Control

When collecting data in the Walr Platform, the system automatically tracks if a question (sub question for question type single/multiple, each row for all other question types) has been asked or not. The reason for not asking a question/row can be because of any logic in the questionnaire (for example, skips, gotos or filters). As soon as a question has been asked or answered, the information is stored in the database.

 

The table below shows the special characters used to filter if a question exists or if it has been asked/answered/not answered.

Addresses:

Description

Special Characters

¤

Existence
Filter \Q1=¤ (Filter: Question existed)
 Filter \Q1=!¤ or !Q1=¤ (Filter: Question did not exist)

.

No answer/unanswered
Filter \Q1=- (Filter: Question was not answered)
 Range=- (Range: No answer is allowed.)

*

Answered
Filter \Q1=* (Filter: Question was answered)
 Range=* (Range: Question must be answered)

?

Filter \Q1=?  (Filter: Question was asked)
 Filter \Q1=!? or !Q1=? (Filter: Question was not asked)

 

The “-“ character, representing no answer, can only be true if the question was asked but no answer was given. This extra information often greatly simplifies the creation of logic in a questionnaire.

 

However, if you want to ask a question only if the respondent answered another question, you can simple specify filter=”\some_question=*”.

 

Likewise, if you want to filter or limit responses based on the response to that question and another question (we don’t care if this was answered), we specify filter=”\some_question=?”. This way, there is no need to repeat complex filters in all questions typically following a gate question. You can do the complex logic in this gate question and then later on, simply refer to the gate question being asked.

 

Syntax Used for Filter Expressions

 

The addressing syntax used for filter expressions varies with the sub question type used:

  • For sub question types: single and multiple, you specify the left-hand side of the filter using the question ID and a sub question letter, and the value on the right-hand side with the “code” value for the row.
  • Example:

For a Gender question with id=”sex” and two rows, Male (code1) and Female (code 2). The filter=”\sex.a=1” meaning Male.

  • If there is only one sub question, one is allowed to type filter=”\sex=102”.

Note: The right hand side of the expression is always a “code” value or index, not a row number.

 

  • For all other sub question types: single-grid, multi-grid, and numeric you need to specify a different address syntax. You specify the left-hand side of the filter using the question ID, sub question letter and the row number. Each element is separated by a period. On the right-hand side is the code value of the column header.
  • For a single-grid or multiple-grid: specify the code value of the column header.

Example: For a Scale question with ID=”grid” and with the code values in the column header of scale 1,2,3,4,5, the syntax will be filter=”\grid.a.1=1”. This means that in the question with ID grid sub question a, in row “1’ (the first row), the user has selected the option corresponding to the code value “1”.

 

  • For a numeric sub question: specify the value or the range that a user should answer for the filter to be true.

Example: For an Age question, if filter=”\age.a.1=20:40”, this means that the user should enter a value between 20 and 40. Again, for this type of question, if there is only one sub question and one row, you can specify filter=”\age=20:40”.

Note: If there are more sub questions and more rows, this will generate a validation error.

 

  • Use the % sign for synchronous filters on sub question types single grid, multi grid, numeric and time: The % sign will be replaced with the row number (if used on the left-hand side in sub question of the mentioned types) or the code value (if used on the right-hand side corresponding to each row in succession).

Example: If you start with a question (Q1) that is a multiple choice, “Which of these cars do you know?” and the second question (Q2) is a single grid, “How would you rate these cars on a scale from 1 to 5, the filter in this sub question can be written as filter=”\Q1.a=%”.

Suppose you follow this up with a third question (Q3), “For cars that get a rating of 4 or 5, allocate 100 points to these cars”. The filter for this third sub question will be filter=”\Q2.a.%=4:5”. The range attribute must be used to tell the system what the sum of all the points should be, as in answer control ”#100”.

 

Note: Often the filter and answer control (range) expressions are usually interconnected in the Walr Platform. A filter is used to determine which questions/sub questions/rows to display, while a range is used to limit or qualify what responses are allowed. In other words, the filter determines which rows to show, while the range specifies what values are allowed to be entered.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.