Scripting > UNICOM Intelligence Function Library > Categorical functions > DefinedCategories
 
DefinedCategories
Returns a set of categories of a categorical variable.
Syntax
DefinedCategories(Val [, Answers])
Parameter
Val
Type: Categorical
Categorical value, used only to specify which MDM object to use.
Answers
Type: None
Optional. Variant value of type Categorical or Text, specifying a set of categories. If omitted, all categories from the VariableInstance are returned.
(return)
Type: Categorical
Set of category numbers as defined in the VariableInstance.
Remarks
Val may refer to any type of MDM object that has elements, for example, Field, Array , Grid or VariableInstance, or it may be an Elements list itself.
If Answers is of type Text, it is assumed to be a category expression and is resolved to a list of categories. If Answers is of type Categorical and contains category names, they are converted to category numbers.
This function requires the case data to be opened with an MDM document or for a script to have an open MDM document available to it. Otherwise, an error will occur. For more information about opening a MDM document in a script, see Value resolution.
If the current value is NULL, Val is an empty Categorical value ({}) and the return value is also an empty Categorical value. If Answers is NULL, the return value is all of the categories defined in the current variable.
Example
This example shows how the DefinedCategories function can be used in an SQL query on a multiple response variable to define groups based on the categories.
SELECT groupby.col[0] AS Museums,
  BASE(museums) AS 'Base'
FROM vdata
WHERE museums IS NOT NULL
GROUP BY museums ON museums.DefinedCategories()
Here is the result set:
Museums Base
------------------------------------- -------
{national_museum_of_science} 333
{museum_of_design} 92
{institute_of_textiles_and_fashion} 47
{archeological_museum} 26
{national_art_gallery} 19
{northern_gallery} 21
{other} 37
{not_answered} 0
See Advanced SQL queries for additional examples of using DefinedCategories in SQL queries.
See also
Categorical functions