89.5 65.4 75.3 77.7 89.3
73.7 87.3 89.9 98.2 35.6
75.8 82.1 98.2 93.5 67.7
101.3 86.5 59.2 35.6 75.7
;
proc print data=temps;
title 'Temperature Measures for Two Cities';
run;
The following data set Temps contains the values of the variables rounded to the nearest
whole number.
Output 25.2 Using a Multidimensional Array
The previous example can also use the DIM function to produce the same result:
do
i=1 to dim1(temprg);
do j=1 to dim2(temprg);
temprg{i,j}=round(temprg{i,j});
end;
end;
The value of DIM1(TEMPRG) is 2; the value of DIM2(TEMPRG) is 5.
Specifying Array Bounds
Identifying Upper and Lower Bounds
Typically in an ARRAY statement, the subscript in each dimension of the array ranges
from 1 to n, where n is the number of elements in that dimension. Thus, 1 is the lower
bound and n is the upper bound of that dimension of the array. For example, in the
following array, the lower bound is 1 and the upper bound is 4:
array new{4} Jackson Poulenc Andrew Parson;
In the following ARRAY statement, the bounds of the first dimension are 1 and 2 and
those of the second dimension are 1 and 5:
array test{2,5} test1-test10;
Bounded array dimensions have the following form:
{<lower-1:>upper-1<,…<lower-n:>upper-n>}
Therefore, you can also write the previous ARRAY statements as follows:
array new{1:4} Jackson Poulenc Andrew Parson;
Specifying Array Bounds 575
array test{1:2,1:5} test1-test10;
For most arrays, 1 is a convenient lower bound, so you do not need to specify the lower
bound. However, specifying both the lower and the upper bounds is useful when the
array dimensions have beginning points other than 1.
In the following example, ten variables are named Year76 through Year85. The
following ARRAY statements place the variables into two arrays named First and
Second:
array first{10} Year76-Year85;
array second{76:85} Year76-Year85;
In the first ARRAY statement, the element first{4} is variable Year79, first{7} is Year82,
and so on. In the second ARRAY statement, element second{79} is Year79 and
second{82} is Year82.
To process the array names Second in a DO group, make sure that the range of the DO
loop matches the range of the array as follows:
do i=76 to 85;
if second{i}=9 then second{i}=.;
end;
Determining Array Bounds: LBOUND and HBOUND Functions
You can use the LBOUND and HBOUND functions to determine array bounds. The
LBOUND function returns the lower bound of a one-dimensional array or the lower
bound of a specified dimension of a multidimensional array. The HBOUND function
returns the upper bound of a one-dimensional array or the upper bound of a specified
dimension of a multidimensional array.
The form of the LBOUND and HBOUND functions is as follows:
LBOUNDn(array-name)
HBOUNDn(array-name)
where
n
is the specified dimension and has a default value of 1.
You can use the LBOUND and HBOUND functions to specify the starting and ending
values of the iterative DO loop to process the elements of the array named Second:
do i=lbound{second} to hbound{second};
if second{i}=9 then second{i}=.;
end;
In this example, the index variable in the iterative DO statement ranges from 76 to 85.
When to Use the HBOUND Function Instead of the DIM Function
The following ARRAY statement defines an array containing a total of five elements, a
lower bound of 72, and an upper bound of 76. It represents the calendar years 1972
through 1976:
array years{72:76} first second third fourth fifth;
To process the array named YEARS in an iterative DO loop, make sure that the range of
the DO loop matches the range of the array as follows:
576 Chapter 25 Array Processing

Get SAS 9.4 Language Reference, 6th 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.