Processing Variables with Arrays |
Creating One-Dimensional
Arrays |
Defining an Array
To group previously defined data set variables into an array, use an ARRAY statement. |
General form, ARRAY statement:
where
|
For example, in the data set Finance.Sales91, you might want to process the variables Qtr1-Qtr4 in the same way. |
Description of Finance.Sales91
|
To group the variables in the array, first give the array a
name. In this example, make the array name sales.
array sales {4} qtr1 qtr2 qtr3 qtr4; Following the array name, you must specify the dimension of the array. The dimension describes the number and arrangement of elements in the array. There are several ways to specify the dimension; in a one-dimensional array such as this one, you can simply specify the number of array elements. The array elements are the existing variables that you want to reference and process elsewhere in the DATA step. array sales {4} qtr1 qtr2 qtr3 qtr4; You can also indicate the dimension of a one-dimensional array by using an asterisk (*), as long as you also specify the elements of the array. This way, SAS software determines the dimension of the array by counting the number of elements. array sales {*} qtr1 qtr2 qtr3 qtr4; |
Enclose the dimension in either braces, brackets, or parentheses. |
( ) array sales {4} qtr1 qtr2 qtr3 qtr4; [ ] When specifying the elements of an array, you can list each variable name that you want to include in the array. When listing elements, separate each element with a space. As with all SAS statements, you end the ARRAY statement with a semicolon (;). array sales{4} qtr1 qtr2 qtr3 qtr4;
Array elements must be either all numeric or all character. You can also
specify array elements as a
variable list. Here is
an example of an ARRAY statement that groups the variables array sales{4} qtr1-qtr4; |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.