
Two-Dimensional Array
The following figure is a conceptual representation of the two-dimensional array
Expenses.
Figure 23.2 Example of a Two-Dimensional Array
Ho t e l
Ph on e
Pe r s . Au t o
Re n t a l Car
Ai r f a r e
Due s
Re g i s t r a t i o n
F e es
Ot he r
Ti p s ( n o n- me al )
Me al s
1
ho t e l 1
ph o ne 1
pe r a u t 1
c a r r nt 1
a i r l i n1
du e s 1
r e gf e e 1
o t h e r 1
t i p s 1
me a l s 1
2
ho t e l 2
ph o ne 2
pe r a u t 2
c a r r nt 2
a i r l i n2
du e s 2
r e gf e e 2
o t h e r 2
t i p s 2
me a l s 2
3
ho t e l 3
ph o ne 3
pe r a u t 3
c a r r nt 3
a i r l i n3
du e s 3
r e gf e e 3
o t h e r 3
t i p s 3
me a l s 3
4
ho t e l 4
ph o ne 4
pe r a u t 4
c a r r nt 4
a i r l i n4
du e s 4
r e gf e e 4
o t h e r 4
t i p s 4
me a l s 4
5
ho t e l 5
ph o ne 5
pe r a u t 5
c a r r nt 5
a i r l i n5
du e s 5
r e gf e e 5
o t h e r 5
t i p s 5
me a l s 5
6
ho t e l 6
ph o ne 6
pe r a u t 6
c a r r nt 6
a i r l i n6
du e s 6
r e gf e e 6
o t h e r 6
t i p s 6
me a l s 6
7
ho t e l 7
ph o ne 7
pe r a u t 7
c a r r nt 7
a i r l i n7
du e s 7
r e gf e e 7
o t h e r 7
t i p s 7
me a l s 7
8
ho t e l 8
ph o ne 8
pe r a u t 8
c a r r nt 8
a i r l i n8
du e s 8
r e gf e e 8
o t h e r 8
t i p s 8
me a l s 8
1
2
3
4
5
6
7
8
9
10
First
Dimension
Expense
Categories
Second
Dimension
Days of the Week Total
The Expenses array contains ten groups of eight variables each. The ten groups (expense
categories) comprise the first dimension of the array, and the eight variables (days of the
week) comprise the second dimension. To reference the data in the array variables, use
the form Expenses{m,n}, where m is the element number in the first dimension of the
array, and n is the element number in the second dimension of the array. Expenses{6,4}
references the value of dues for the fourth day (the variable is Dues4).
Syntax for Defining and Referencing an Array
To define a simple or a multidimensional array, use the ARRAY statement. The
ARRAY statement has the following form:
ARRAY array-name {number-of-elements} <$> <length> <array-elements> <(initial-value-list)>;
where
array-name
is a SAS name that identifies the group of variables.
number-of-elements
is the number of variables in the group. You must enclose this value in either
parentheses (), braces {}, or brackets [].
$
specifies that the elements in the array are character elements.
Syntax for Defining and Referencing an Array 533
Get SAS 9.4 Language Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.