multiResponseSet Property (Python)

The multiResponseSet property of a Dataset object gets or sets multiple response sets for the dataset. The multiResponseSet property behaves like a Python dictionary in terms of getting, setting, and deleting values. A Python dictionary consists of a set of keys, each of which has an associated value that can be accessed simply by specifying the key. In the case of multiple response sets, each key is the name of a set and the associated value specifies the details of the set.

  • The multiple response set name is a string of maximum length 63 bytes that must follow IBM® SPSS® Statistics variable naming conventions. If the specified name does not begin with a dollar sign ($), then one is added. If the name refers to an existing set, the set definition is overwritten.
  • When setting a multiple response set, the details of the set are specified as a list or tuple with the following elements in the presented order.

    mrsetLabel. A string specifying a label for the set. The value cannot be wider than the limit for IBM SPSS Statistics variable labels.

    mrsetCodeAs. An integer or string specifying the variable coding: 1 or "Categories" for multiple category sets, 2 or "Dichotomies" for multiple dichotomy sets.

    mrsetCountedValue. A string specifying the value that indicates the presence of a response for a multiple dichotomy set. This is also referred to as the “counted” value. If the set type is numeric, the value must be a string representation of an integer. If the set type is string, the counted value, after trimming trailing blanks, cannot be wider than the narrowest elementary variable.

    varNames. A tuple or list of strings specifying the names of the elementary variables that define the set (the list must include at least two variables).

  • When getting a multiple response set, the result is a tuple of 5 elements. The first element is the label, if any, for the set. The second element specifies the variable coding--'Categories' or 'Dichotomies'. The third element specifies the counted value and only applies to multiple dichotomy sets. The fourth element specifies the data type--'Numeric' or 'String'. The fifth element is a list of the elementary variables that define the set.

Retrieving Multiple Response Sets. You retrieve multiple response sets for a dataset from the multiResponseSet property of the associated Dataset object. You retrieve the value of a particular set by specifying the set name, as in:

dsObj = spss.Dataset()
mrset = dsObj.multiResponseSet['setName']

You can iterate through the multiple response sets using the data property, as in:

dsObj = spss.Dataset()
for name, set in dsObj.multiResponseSet.data.iteritems():
   print name, set

Adding and Modifying Multiple Response Sets. You can add new multiple response sets and modify details of existing ones. For example:

dsObj.multiResponseSet['$mltnews'] = \
                       ["News Sources",2,"1",["Newspaper","TV","Web"]]
  • If the set $mltnews exists, it is updated with the specified values. If the set $mltnews doesn't exist, it is added to any existing ones for the dataset.

Resetting Multiple Response Sets. You can reset the multiple response sets associated with a dataset. For example:

dsObj.multiResponseSet = \
{'$mltnews':["News Sources",2,"1",["Newspaper","TV","Web"]],
 '$mltent':["Entertainment Sources",2,"1",["TV","Movies","Theatre","Music"]]}
  • You reset the multiple response sets by setting the multiResponseSet property to a new Python dictionary. Any existing multiple response sets are cleared and replaced with the specified ones.

Deleting Multiple Response Sets. You can delete a particular multiple response set or all sets. For example:

#Delete a specified set
del dsObj.multiResponseSet['setName']
#Delete all sets
del dsObj.multiResponseSet