Indexed Variables


Indexed variables let you stack and align data, eliminating the need to derotate data or to assign specific columns for different variables. You create indexed variables using the INDEX statement. IDX and I# let you access indexed variables defined in the Glossary.


Typical uses of indexed variables include:

With indexed variables, data for similar questions are stacked atop one another and referred to by a composite variable name. When indexed variables are used together, individual levels are aligned so that a code value found in one indexed variable pulls out codes on only that same level in the other indexed variable.


The INDEX Instruction


Use the INDEX instruction to create indexed variables in the glossary. First, you define the variables, ‘stacking’ similar variables together. Variables stacked atop each other must be the same width. You write INDEX, followed by the variables in braces:


INDEX {variable 1, variable 2, . . .}

INDEX {variable 3, variable 4, . . .}

INDEX {variable 5, variable 6, . . .}


results in variables 1, 3 and 5 stacked atop each other and variables 2, 4 and 6 stacked atop each other.


I# Notation


After the variables have been defined, they can be referred to by an I (upper case) followed by the variable number:




where # refers to the order in which the variable appears in the INDEX statement. The I# notation can be used in any logic statement for table, banner or glossary logic.


For example, the first group of variables in the above example (1, 3 and 5) can be referred to as I1. The second group of variables (2, 4 and 6) can be referred to as I2.


Continuing with the example, when I1 is used in a row run against I2 in a banner, filter or in the same row, the levels in that composite variable are matched up. For example, the statement:


I1(4) AND I2 (35)


is true only if there is a:


4 in variable 1 AND a 35 in variable 2


4 in variable 3 AND a 35 in variable 4


4 in variable 5 AND a 35 in variable 6.


IDX Notation

To refer to individual levels in indexed variables, use an IDX followed by the level number(s) in parentheses:


IDX (Level#-Level#, Level#)


You can indicate consecutive levels using hyphens (for example: IDX(1-3)) and separate multiple levels with commas (for example: IDX (2,4,7)).


For example, to refer to only codes of 4 in variable I1 on levels 2 and 3, you would write:


I1 (4) AND IDX (2,3)


The 2 and 3 refer to the second and third INDEX statement.


Note: You cannot use more than one reference to IDX in complex logic (for example, {IDX (1) AND Q1 (1)} OR {IDX (4) AND Q2 (1)})


Using Indexed Variables with RECODE, ASSIGN, and COMPUTE Statements

Indexed variables can be manipulated with the RECODE, ASSIGN and COMPUTE statements. When indexed variables are used with these statements, many blocks of glossary statements can be reduced.


You can use the Repeat feature with INDEX. Repeat lets you apply an INDEX command to multiple columns.


See Indexed variables examples for examples of RECODE and ASSIGN. See COMPUTE and Repeat for examples of those features with indexed variables.


Indexed variables cannot be used with the DECLARE instruction or used within IF/ELSE or Looping logic.


Note: You can use the View|INDEX Statement Map option to display INDEX statements from the Glossary in an easy-to-read grid that can be saved to an Excel file. This can be especially helpful if your INDEX statements are long and/or you are using the Repeat (R) feature.

Related topics:

View|INDEX Statement Map

Line Tables