Defining Data Objects, 7 of 11

## Defining Variables

A variable is an object that stores data. All of the data in a variable represents the same unit of measurement with the same data type. Your business might have several categories of transactions (measured in dollars, units, percentages, and so on) and each category is stored in its own variable. For example, you might record sales data in dollars (a `sales` variable) and units (a `units` variable).

Typically, you use variables to contain data values that quantify a particular aspect of your business.

### Types of Variables

Variables can be either dimensioned or undimensioned:

• Dimensioned variables. If a variable is an array with dimensions, then those dimensions organize its data, and there is one cell for each combination of dimension values. This type of variable is called a dimensioned variable. A variable can be dimensioned by up to 32 dimensions.
• Undimensioned variables. If a variable has no dimensions, then it is a scalar, or single-cell variable, which contains one data value.

Variables that you define in an analytic workspace can be permanent or temporary. You can also define variables in programs, as described in "Defining Local Variables".

A permanent variable is a variable for which both the variable values and definitions are stored in an analytic workspace.

Temporary variables have values only during the current session. When you update and commit the analytic workspace, only the definitions of temporary variables are saved. When you exit from the analytic workspace, the data values are discarded.

### How Variable Data Is Stored

The order in which you list the dimensions in a variable definition determines how the data of that variable is stored and accessed. The first dimension in the variable definition is the fastest-varying dimension, and the last dimension is the slowest-varying dimension.

For example, assume your analytic workspace has an `opcosts` variable that contains the operating costs, by month, of each city in which you have offices. In the definition shown below for the `opcosts` variable, `month` is the fastest-varying dimension and `city` is the slowest-varying dimension.

```DEFINE opcosts VARIABLE DECIMAL <month city>

```

The data for a multidimensional variable is stored as a linear stream of values, in which the values of the fastest-varying dimension are clustered together. For example, for the `opcosts` variable, the values for Boston for all the months are stored in a sequence, and then it stores the values for Chicago for all the months in a sequence, and so on. Thus the month values vary fastest in the `opcosts` variable, as shown in the following table.

Dimension  Values  JAN97
BOSTON
FEB97
BOSTON
. . .
. . .
DEC97
BOSTON
JAN97
CHICAGO
. . .
. . .

Variable  Values

16000.77

16000.28

. . .

16000.98

19000.24

. . .

When you define variables and other dimensioned objects, and when you write programs that loop over multidimensional expressions in nested loops, you should always try to maximize performance by matching the fastest-varying dimension with the inner loop.