![]() Chapter Contents |
![]() Previous |
![]() Next |
| ARRAY |
| Valid: | in a DATA step |
| Category: | Information |
| Type: | Declarative |
Syntax |
|
ARRAY array-name { subscript }
<$><length>
<array-elements> <(initial-value-list)>; |
| Restriction: | Array-name must be a SAS name that is not the name of a SAS variable in the same DATA step. |
| Tip: | In this book, the subscript is enclosed in braces ({}). Brackets ( [ ] ) and parentheses (( )) are also allowed. |
| Example: |
An array with one dimension
can be defined as
array simple{3} red green yellow;This ARRAY statement defines an array that is named SIMPLE that groups together three variables that are named RED, GREEN, and YELLOW. |
| Example: |
An array with more than
one dimension is known as a multidimensional array. You can have any number
of dimensions in a multidimensional array. For example, a two-dimensional
array provides row and column arrangement of array elements. This statement
defines a two-dimensional array with five rows and three columns:
array x{5,3} score1-score15;SAS places variables into a two-dimensional array by filling all rows in order, beginning at the upper-left corner of the array (known as row-major order). |
| Range: | In most explicit arrays, the subscript in each dimension of the array ranges from 1 to n, where n is the number of elements in that dimension. |
| Example: |
In the following example,
the value of each dimension is by default the upper bound of that dimension.
array x{5,3} score1-score15;As an alternative, the following ARRAY statement is a longhand version of the previous example: array x{1:5,1:3} score1-score15; |
| Restriction: | You cannot use the asterisk with _TEMPORARY_ arrays or when you define a multidimensional array. |
| Tip: | The dollar sign is not necessary if the elements have been previously defined as character elements. |
To specify an iteration factor and nested sublists for the initial values, use the following format:
<constant-iter-value*> <(>constant value | constant-sublist<)>
| Details |
| Comparisons |
| Examples |
array rain {5} janr febr marr aprr mayr;
array days{7} d1-d7;
array month{*} jan feb jul oct nov;
array x{*} _NUMERIC_;
array qbx{10};
array meal{3};
array test{4} t1 t2 t3 t4 (90 80 70 70);
array test{4} t1-t4 (90 80 2*70);
array test{4} _TEMPORARY_ (90 80 70 70);
array new{2:5} green jacobs denato fetzer;
array x{5,3} score1-score15;
array test{3:4,3:7} test1-test10;
array temp{0:999} _TEMPORARY_;
| See Also |
Statement:
| |||
| Array Processing in SAS Language Reference: Concepts |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.