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 standalone variable.
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
Complete the following steps to add a variable from a tool parameter:
- Complete the steps to open a model and add data and tools if necessary.
- 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.
- 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 standalone variable
A standalone 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.
Complete the following steps to add a standalone variable to the model diagram:
- Complete the steps to open a model, connect to an analysis session, and activate the model if necessary.
- 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.
- For Choose the variable structure, choose Multiple values if necessary.
- For Choose the variable data type, expand the menu and choose a different option if necessary.
- 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 has to 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
Complete the following steps to draw a connection between variable and tool elements:
- Complete the steps to open a model and add data, tools, and variables if necessary.
- 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.
- 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
Complete the following steps to connect variables through an analysis tool:
- Complete the steps to open a model and add data, tools, and variables if necessary.
- Select a tool element and click Open
on the element toolbar, or double-click the tool element to open it. - 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.
- Click a variable to select it.
The variable is added to the parameter.
- 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.
Complete the following steps to update an input data variable:
- Complete the steps to open the ModelBuilder pane and add a variable if necessary.
- 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.
- Do one of the following:
- For double or integer variables, type a number into 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 into the text box and click Add or press Enter between each number. To remove numbers, click the remove button
for the value. - For feature layer or 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 string variables, type a text value into the text box. If the variable is already connected to an analysis tool, the variable may display a menu of options.
- 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. Single value variables are supported for feature layer, table, double, integer, string, and linear unit data types.
- 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:
- Double—Numbers with decimal places. This data type is supported for both single value and multiple value structures.
- Feature layer—Hosted feature layer item.
- Integer—Numbers without decimal places. Negative values are supported in the variable, but are not supported for all tool parameters.
- Linear unit—Numbers and units.
- String—Alphanumeric and special characters.
- Table—Hosted table items.
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.
The following tool parameters do not support adding a variable from the parameter, but do support connecting a standalone variable:
| Tool | Parameter | Variable type |
|---|---|---|
Join Features | Target layer | Feature layer or table |
Join layer | ||
Calculate Composite Index | Input features or table | |
Filter by Attributes | Input dataset | |
Calculate Field | Input dataset | |
Aggregate Points | Bin size | Linear unit |
Summarize Within | Bin size | |
Enrich Layer | Measurement value | |
Generate Tessellations | Bin size |