ASSIGN command

Creates a variable and assigns a value to the variable.

Syntax

ASSIGN variable_name = value <IF test>

Tip

You can omit the ASSIGN keyword because Analytics automatically interprets the following syntax as an assignment operation:

variable_name = value

Parameters

Name Description
variable_name

The name of the variable to assign the value to. If the variable does not exist, it is created. If the variable already exists, it is updated with the new value.

Do not use non-English characters, such as é, in the names of variables. Variable names that contain non-English characters will cause scripts to fail.

Note

Variable names are limited to 31 alphanumeric characters. The name can include the underscore character ( _ ), but no other special characters, or any spaces. The name cannot start with a number.

value

The value to assign to the variable. If a new variable is created, the variable type is based on the data type in value.

IF test

Optional

A conditional expression that must be true to create the variable or assign the value to the variable.

Examples

Assigning a value to a variable

You assign the value of the Amount field in the current record to a variable named v_current_amount. Because v_current_amount is a variable, its value does not change unless explicitly changed by another ASSIGN command:

ASSIGN v_current_amount = Amount

Conditionally assigning a value to a variable

You want to update the value of a variable called v_quantity to 1, but only if the value in another variable called v_counter is less than 10.

If v_counter is greater than or equal to 10, no assignment is made and the value of v_quantity remains unchanged.

Note that the optional ASSIGN keyword is omitted:

v_quantity = 1 IF v_counter < 10

Remarks

Duration of variables

Variables with names that are not prefaced with an underscore are retained for the duration of the current Analytics session only.

If you want a variable to be permanently saved with an Analytics project, preface the variable name with an underscore:

 ASSIGN value = _variable_name

Reassigning variables used in a computed field or GROUP

If you assign a value to an existing variable in the following situations, then the new value is assigned but the previous value's length and decimal count are retained:

  • variables used in computed fields
  • variables reassigned inside a GROUP

The length of the new value is padded or truncated and the decimals are adjusted if required.

If you reassign a variable in any other context, then the previous value as well as its length and decimal specifications are overwritten.

Variables created by Analytics commands

When you execute certain commands, either by entering information in dialog boxes in Analytics or by running scripts, system variables are automatically created by Analytics. You can use these variables, and the values they contain, when processing subsequent Analytics commands.

The value in a system variable is replaced with an updated value if you execute the same command again.

For more information, see Variables created by Analytics commands.