Skip to main content

Add variables

Variables are elements in a model that hold a value or a reference to data. Variables can be used as inputs to an analysis tool. Using variables can make iterating on tool parameters faster because you can change the specific variable values without opening the full tool dialog box. Variables can also be used to share input values for multiple analysis tools.

Add a variable

Variables can be added to a model diagram from a tool parameter or as a stand-alone variable. Adding a variable from a tool parameter is recommended in most cases because it ensures that the correct variable is used for the parameter.

Add a variable from a tool parameter

A variable can be added directly from a tool parameter. Adding a variable from a tool parameter ensures the following:

  • The variable structure and data type are compatible with the chosen tool parameter.

  • The tool parameter's default or user-specified value is automatically populated when applicable.

  • The tool parameter's defined inputs (for example, a menu of supported units) are available in the variable when applicable.

  • The variable is automatically connected to the tool without requiring additional steps.

To add a variable from a tool parameter, complete the following steps:

  1. Complete the steps to open a model and add data and tools if necessary.

  2. Select a tool element, and click Add variable on the element toolbar.

    The Select parameter menu appears listing the tool parameters.

    If Add variable is unavailable, it may mean that you are not connected to an analysis session or the model is not active.

  3. Click a parameter name to select it.

The variable is added to the model diagram and is connected to the tool. If the parameter has a default value, the value is automatically added to the variable, and the variable appears in a ready-to-run state (blue). If there is no default or user-specified value, the variable is empty and appears in a not-ready-to-run state (gray). You can open the element to update the variable value.

Add a stand-alone variable

A stand-alone variable is added to a model diagram without an association to any tool parameters. After the variable is added, it must be connected to a tool to be used by a tool parameter.

To add a stand-alone variable to the model diagram, complete the following steps:

  1. Complete the steps to open a model, connect to an analysis session, and activate the model if necessary.

  2. Click Add variable on the action toolbar.

    The Add variable dialog box appears with options for the variable structure and data type. The default variable structure is Single value, and the default data type is String.

    If Add variable is unavailable, it may mean that you are not connected to an analysis session or the model is not active.

  3. For Choose the variable structure, choose Multiple values if necessary.

    Learn more about variable structures

  4. For Choose the variable data type, expand the menu, and choose a different option if necessary.

    Learn more about supported data types

  5. Click Add.

The variable is added to the model diagram. You can open the element to update the variable value and draw a connection from the variable to a tool element. Variables can only be connected to compatible tool parameters.

Connect variables and tools

After a variable is added to the model diagram, it must be connected to a tool to be used for a tool parameter. Connectors can be added either by drawing directly in the diagram or through a tool dialog box.

Draw a connection

To draw a connection between a variable and tool elements, complete the following steps:

  1. Complete the steps to open a model, and add data, tools, and variables if necessary.

  2. Click the port on the right side of a variable element, and drag it to the port on the left side of a tool element.

    The Select input menu appears listing the compatible tool parameters.

  3. Click the name of the parameter in which the variable will be used (for example, Input layer).

A connector appears between the variable element and the tool element, and the tool validates. The variable value will appear for the specified parameter when the tool dialog box is opened.

Connect variables through an analysis tool

To connect variables through an analysis tool, complete the following steps:

  1. Complete the steps to open a model, and add data, tools, and variables if necessary.

  2. Select a tool element, and click Open on the element toolbar, or double-click the tool element to open it.

  3. Click Select variable next to the parameter for which you are adding the variable.

    The Select variable dialog box appears showing a list of variables in the model that are compatible with the parameter. If no variables are listed, follow the steps to add a variable for the parameter.

  4. Click a variable to select it.

    The variable is added to the parameter.

  5. Update any remaining parameters, and click Confirm to apply the changes.

A connector appears between the variable element and the tool element, and the tool validates.

Update a variable

Variable elements can be opened to add, update, or remove the variable's value.

To update an input data variable, complete the following steps:

  1. Complete the steps to open the ModelBuilder pane, and add a variable if necessary.

  2. Select the variable, and click Open on the element toolbar, or double-click the element to open it.

    A dialog box showing the type of variable appears.

  3. Do one of the following:

    • For areal unit, linear unit, or time unit variables, type a number in the text box or use the up and down arrows to increase or decrease the value. Click the unit value to open a menu, and choose a different unit from the list.

    • For Boolean variables, click the radio button next to the unselected value.

    • For double or integer variables, type a number in the text box or use the up and down arrows to increase or decrease the value.

    • For double (multiple values) variables, type one or more numbers in the text box, and click Add or press Enter between each number. To remove numbers, click the remove button for the value.

    • For enrichment variables, click Variable to open the Data Browser window. Select one or more variables in the window using the filters for region, data collection, or category if necessary.

    • For feature layer, raster layer (beta), and table variables, click the input dataset or Layer button, and select a layer from the list or browse to select a supported layer.

      Note:

      If the feature layer variable is already connected to one or more analysis tools, only datasets compatible with the tools and parameters will be available. If the parameters do not support the same features (for example, one parameter only supports points and one only supports polygons), the variable will not be able to determine which layers are compatible and may result in an error for one or more tools.

    • For field variables, choose a field from the menu. Field variables must be connected to an analysis tool with a connected input data variable to display a menu of fields.

    • For field calculation variables, click Expression, and use Fields , Functions , and basic operators to create a valid SQL-based expression.

    • For SQL query builder variables, click Build new query, and use the Query builder window to build an attribute-based query.

    • For string variables, type a text value in the text box. If the variable is already connected to an analysis tool, the variable may display a menu of options.

    • For complex variables, choose the type of input, and update the value the same way you would update that type of variable. For example, if the complex variable supports feature layers and tables, choose Features or Table, and click Layer to select a feature or table layer.

  4. Click Confirm.

    The variable updates and validates.

Variable structures

Variables support the following structures:

  • Single value—Supports adding a single value of a single data type.

  • Multiple value—Supports adding multiple values of a single data type. Currently, multiple value structures only support Double data types. For example, a double (multiple values) variable can be used in the Distance values parameter for Create Buffers.

    Note:

    Parameters that support multiple value double variables also support one or more single value double variables.

Supported data types

The following data types are supported:

  • Areal unit—Numbers and square units.

  • Boolean—True or false. A value of True is equivalent to turning a toggle button on or checking a check box. A value of False is equivalent to turning a toggle button off or unchecking a check box. For radio button parameters, connect to a tool parameter to see the label from the tool dialog box.

  • Complex—Most complex variables support two different data types, such as feature layer and table. Some complex variables currently only support one data type. The combination of data types supported depends on the parameter used to create the variable. Complex variables can only be added from the tool parameter.

  • Double—Numbers with decimal places. This data type is supported for both single value and multiple value structures.

  • Enrichment variables—Demographic and lifestyle data variables. Enrichment variables can only be added from the tool parameter for Enrich Layer.

  • Feature layer—Hosted feature layer item.

  • Field—Fields from the input dataset (available when connected to an analysis tool with a connected input data variable).

  • Field calculation—An SQL-based expression.

  • Integer—Numbers without decimal places. Negative values are supported in the variable but are not supported for all tool parameters.

  • Linear unit—Numbers and distance units.

  • Raster layer (beta)—Imagery or tiled imagery layer item.

  • SQL query builder—An SQL-based query.

  • String—Alphanumeric and special characters. When connected to a tool parameter, a menu of supported options will be available.

  • Table—Hosted table item.

  • Time unit—Numbers and time units.

Limitations

Tool parameters that accept string variables have defined lists of accepted input values (for example, a menu of supported units). It is recommended that you add string variables from a tool parameter or connect the variable to a tool parameter before updating the variable value. Typing a value into a disconnected string variable may result in errors.

Creating a new field is not currently supported when a field variable is used in the Field to calculate parameter for Calculate Field.