Comparing values in AskiaScript

Note: This topic provides descriptions and examples of how to compare values in multi-coded variables, and between two or more variables, using AskiaScript. It assumes you already know how to define AskiaScript conditions. For an introduction to creating custom routing conditions, see custom routing conditions in AskiaScript. A full description of the AskiaScript language can be found here.

The AskiaDesign training course provides a broad introduction to routing instructions in AskiaDesign (contact Askia if you would like to arrange training sessions). However, the Askia system provides several more powerful routing capabilities that go beyond the scope of the course. This topic explains how to compare the values in multi-coded variables, and between two or more variables, in order to create sophisticated complex script conditions.

This topic covers:

Checking and comparing responses in multi-coded questions

The following operators allow you to specify specific groups of response items in a routing condition. They are useful when working with data from multi-coded questions (for example, “=” would not work with a multi-coded question, because more than one response might be selected). The objective is to create conditions which return 1 when you wish the set of answers to be selected and which return 0 when you don't. 1 is considered true; 0 is considered false.

Has

This function checks that at least one of the referenced response items was selected. If this is the case, the function returns 1; otherwise, it returns 0. For example:

Q1 Has {2;3}

will return 1 if either the second or third response were selected.

HasNone

This is the opposite of Has. It returns 1 if none of the specified response items were selected by the respondent. For example:

Q1 HasNone {2;3}

will return 1 if the second and third response were not selected.

HasAll

This function checks that all of the referenced response items were selected. Note that other responses may be selected as well, and the function will still return 1. For example:

Q1 HasAll {2;3}

will return 1 if the respondent answered 1, 2 and 3.

HasAndNoOther

This function checks that at least one of the specified responses was selected by the respondent. However, if any responses not in the list were selected, then the function returns 0. For example:

Q1 HasAndNoOther {2;3}

will return 1 if the respondent selected response 2. If she selected responses 1 and 2, the function will return 0 (because 1 is not in the list).

HasAllandNoOther

This is similar to HasAll, but returns 0 if the respondent selected any responses other than those in the list. In other words, the selected response must match the list exactly. So:

Q1 HasAllAndNoOther {2;3}

will return 1 if the respondent answered 2 and 3, but 0 if she answered 1, 2 and 3 (because 1 is not in the list of qualified values).

Comparing numeric values

The following numeric operators allow you to compare the values of two statements. For example, they can be used to determine the value stored in a numeric question.

Equal to

= is true if the first value is equal to the second value. For example:

Q2 = 3

is true if the value in Q2 is 3.

Not equal to

<> is true if the first value is not equal to the second value. For example:

Q2 <> 3

is true if the value in Q2 is not 3.

Greater than; Greater than or equal to

> is true if the first value is greater than the second value. For example:

Q2 > 3

returns is true if the value in Q2 is greater than 3.

>= is true if the first value is greater than or equal to the second value. For example:

Q2 >= 3

is true if the value in Q2 is greater than or equal to 3.

Less than; Less than or equal to

< is true if the first value is less than the second value. For example:

Q2 < 3

returns true if the value in Q2 is less than 3.

<= is true if the first value is less than or equal to the second value. For example:

Q2 <= 3

is true if the value in Q2 is less than or equal to 3.

Using Size( ) or .Count to get the number of answers given to a multi-coded question

These functions allow you to determine the number of responses selected in a multi-coded question. For example:

Size(??Q1??) 'askiascript 1.0

Q1.Answers.Count 'askiascript 2.0

Each of these returns 3 if the respondent has selected 3 responses in that question and zero if no response has been selected (where this is allowed). This can be combined with a numeric comparison to create a logical test. For example, identify responses where more than 3 answers had been given, the script would be:

Size(??Q1??) > 3 'askiascript 1.0

Q1.Answers.Count > 3 'askiascript 2.0

or, if no responses had been given (i.e. 0 answers):

Size(??Q1??) = 0 'askiascript 1.0

Q1.Answers.Count = 0 'askiascript 2.0

Create your own Knowledge Base