Scripting > UNICOM Intelligence Function Library > Miscellaneous functions > CategorizeLoopVariable
 
CategorizeLoopVariable
Converts the value of a Numeric, Text, or Date value to a Categorical value according to the definition of the specified categorical loop variable.
Syntax
CategorizeLoopVariable(Val, CategorizedVariable)
Parameters
Val
Type: None
Variant value of type Long, Double, Text, or Date
CategorizedVariable
Type: Text
The name of the categorical loop variable, which will be used to ensure the generated category name exists and to check if Other and NA should be used.
(return)
Type: None
The converted categorical value related to Val.
Remarks
The function looks up in the parent level of the current level for the CategorizedVariable and checks to see if the parent supports IArray or the parent is the document level. If no parent level exists for the given CategorizedVariable, an error is returned.
The conversion is based on the definition of the categorical loop variable named in the CategorizedVariable parameter. The conversion process starts by generating an MDM name from the value Val. The MDMName function is used for this process.
When a generated category name does not exist in the specified categorical loop variable, the ‘Other’ category is returned (if it exists), otherwise the empty categorical, {}, is returned.
If the value is an empty string and ‘NA’ is not defined, an empty categorical, {}, is returned.
If the value is Null and ‘NA’ is not defined, NULL is returned.
Example
Model "Model"
loop [1..3] fields -
(
DBID "DBID"
text [1..20]
{
Audi1 "Audi1" factor("Audi1"),
BMW1 "BMW1" factor("BMW1"),
Ferrari1 "Ferrari1" factor("Ferrari1")
};

) column expand;
The following is the metadata script for the derived variable in the “Model” helper fields:
DBCodes "q1 label"
categorical
{
BMW1 "BMW1"
[
Value = 6
]
fix keycode("Ctrl+1") factor("BMW1"),
other("Other" "Other"
[
IsUserDefined = true,
IsForeverHidden = true
]
text ) keycode("Ctrl+2")
} expression("SUM(Model.(CategorizeLoopVariable(DBID,""Model.DBCodes"")))", NoDeriveElements) usagetype("HelperField");
The following result is returned:
Result = CategorizeLoopVariable(DBID, "Model.DBCodes")
DBID
Result (NA if defined)
Result (NA is not defined)
"BMW1"
{BMW1}
{BMW1}
"Audi1"
{other}
{other}
" "
{NA}
{ }
NULL
{NA}
NULL
See also
Miscellaneous functions