Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Logical expressions > Checking categorical responses > A given number of specified responses chosen
 
A given number of specified responses chosen
To test whether the respondent chose a given number of answers from a set of responses, as in, did the respondent choose three track and field sports from a selection of sports, use the ContainsSome function.
For more information, see ContainsSome.
Syntax
ContainsSome({<response_1>, <response_2>, ... <response_n>}[, <minimum>][, <minimum>][, <no_others>])
Parameters
<question_name>
The name of the question whose response you want to check.
<response_1> to <response_n>
The names of the responses you want to check for.
<minimum>
The minimum number of responses that must be chosen from the set in order for ContainsSome to be True.
The default is zero meaning that none of the specified responses need be chosen.
<maximum>
The maximum number of responses that must be chosen from the set in order for ContainsSome to be True.
The default is the number of responses specified in the expression.
<no_others>
True if the response can contain only answers from the specified set, or False if other answers can be chosen too.
The default is False.
Example
If the Sports question is defined in the Metadata section as:
Sports "Which sports do you take part in?" categorical [1..]
{
  Running, Cycling, Football, Javelin, Discus,
  HighJump "High jump", LongJump "Long jump",
  Swimming, Basketball, Tennis, Hockey, Rugby,
  PoleVault "Pole vault", Netball, Gymnastics
};
and you want to test whether the respondent’s answer contains between three and five track and field events, you would write the following expression:
Sports.ContainsSome({Running,Javelin,Discus,HighJump,LongJump,
    PoleVault}, 3, 5)
This expression ignores any other sports that might be present in the response to the Sports question, and has the same effect as:
Sports.ContainsSome({Running,Javelin,Discus,HighJump,LongJump,
    PoleVault}, 3, 5, false)
If you want to take other sports into account and test whether the respondent mentioned only three, four, or five track and field events and no other sports, you would write:
Sports.ContainsSome({Running,Javelin,Discus,HighJump,LongJump,
    PoleVault}, 3, 5, true)
You can leave the minimum and/or maximum number of required responses undefined, and the interviewing program will use the function’s default settings instead. The default minimum is one, so the expression:
Sports.ContainsSome({Running,Javelin,Discus,HighJump,LongJump,
    PoleVault}, 5)
is True if the respondent’s answer contains between one and five of the specified sports. It is False if all six sports or none are mentioned. The results of the expression are unaffected by any other sports mentioned.
Similarly, if the expression is:
Sports.ContainsSome({Running,Javelin,Discus,HighJump,LongJump,
    PoleVault}, 3)
the result is True if the respondent mentions at least three of the specified sports, regardless of any other sports mentioned.
See also
Checking categorical responses