Working with multi-coded data and other sets in AskiaScript

Note: This topic provides descriptions and examples of how to compare values from two existing sets of values, how to merge these values using an AskiaScript expression, and how to extract random values from a set. 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 explains how to compare the values in multi-coded variables, and between two or more variables, in order to sophisticated script conditions.

This topic describes the following AskiaScript functions:

Set controlEdit

Intersection

This function retrieves the common values of two sets. It can be used to:

Below, you will find an example of each.

Comparing the selected responses to two questions, and discover which were selected in both:

Q1 Intersection Q2

If Q1={2;4} (i.e. responses 2 and 4 were selected) and Q2={3;4;7} (responses 3, 4 and 7 were selected), the function will return {4}.

Checking whether one or more responses in a specific list were selected:

Q1 Intersection {3;5;9}

If Q1={2;4}, the function will return nothing.

Checking whether at least one response from a list was selected:

({3;5;9} Intersection Q1) <> {}

tests whether one or more of the specified responses (3, 5 and 9) were selected. if Q1={2;4}, the function will return 0. If Q1={3;4}, the function will return 1.

Testing whether no responses in a list were selected:

({3;5;9} Intersection Q1) = {}

tests whether none of the listed responses (3, 5 and 9) were selected. if Q1={2;4}, the function will return 1. if Q1={3;4}, the function will return 0.

Union or +

Use this function to merge the values contained in two different sets, such as the responses to two questions. You can use union or + interchangeably.

For example:

{} + Q1 Union Q2 or {} + Q1 + Q2

if Q1={2;4} and Q2={3;7}, the function will return {2;4;3;7}.

{} + Q1 Union {5;10}

if Q1={2;4}, the function will return {2;4;5;10}.

SelectRandom

This function allows you to select the specified number of values at random from a specific set, for example from the responses given to a multi-coded question. The first parameter is the set, and the second is the number of values to select. Examples:

SelectRandom(??Q2??, 2) 'askiascript 1.0

Q2.Answers.Index.SelectRandom(2) 'askiascript 2.0

This will select two of the responses selected at Q2.

SelectRandom({5 To 10}, 3) 'askiascript 1.0

({5 to 10}).SelectRandom(3) 'askiascript 2.0

This will randomly select three values from 5, 6, 7, 8, 9 and 10 (such as 5, 6, and 9).

Create your own Knowledge Base