Previous Page | Next Page

Statements

Array Reference Statement



Describes the elements in an array to be processed.
Valid: in a DATA step
Category: Information
Type: Declarative

Syntax
Arguments
Details
Comparisons
Examples
Example 1: Using Iterative DO-Loop Processing
Example 2: Referencing Many Arrays in One Statement
Example 3: Specifying the Subscript
Example 4: Using the Asterisk References as a Variable List
See Also

Syntax

array-name { subscript }


Arguments

array-name

is the name of an array that was previously defined with an ARRAY statement in the same DATA step.

{subscript}

specifies the subscript. Any of these forms can be used:

{variable-1< , ...variable-n>}

specifies a variable, or variable list that is usually used with DO-loop processing. For each execution of the DO loop, the current value of this variable becomes the subscript of the array element being processed.

Featured in: Using Iterative DO-Loop Processing
Tip: You can enclose a subscript in braces ( { } ), brackets ( [ ] ), or parentheses (( )).
{*}

forces SAS to treat the elements in the array as a variable list.

Tip: The asterisk can be used with the INPUT and PUT statements, and with some SAS functions.
Tip: This syntax is provided for convenience and is an exception to usual array processing.
Restriction: When you define an array that contains temporary array elements, you cannot reference the array elements with an asterisk.
Featured in: Using the Asterisk References as a Variable List
expression-1< , . . . expression-n>

specifies a SAS expression.

Range: The expression must evaluate to a subscript value when the statement that contains the array reference executes. The expression can also be an integer with a value between the lower and upper bounds of the array, inclusive.
Featured in: Specifying the Subscript

Details


Comparisons


Examples


Example 1: Using Iterative DO-Loop Processing

In this example, the statements process each element of the array, using the value of variable I as the subscript on the array references for each iteration of the DO loop. If an array element has a value of 99, the IF-THEN statement changes that value to 100.

array days{7} d1-d7;
   do i=1 to 7;
      if days{i}=99 then days{i}=100;
   end;


Example 2: Referencing Many Arrays in One Statement

You can refer to more than one array in a single SAS statement. In this example, you create two arrays, DAYS and HOURS. The statements inside the DO loop substitute the current value of variable I to reference each array element in both arrays.

array days{7} d1-d7;
   array hours{7} h1-h7;
      do i=1 to 7;
         if days{i}=99 then days{i}=100;
         hours{i}=days{i}*24;
      end;


Example 3: Specifying the Subscript

In this example, the INPUT statement reads in variables A1, A2, and the third element (A3) of the array named ARR1:

array arr1{*} a1-a3;
x=1;
input a1 a2 arr1{x+2};


Example 4: Using the Asterisk References as a Variable List


See Also

Function:

DIM Function

Statements

ARRAY Statement

DO Statement, Iterative

Array Processing in SAS Language Reference: Concepts

Previous Page | Next Page | Top of Page