DIM Function


Returns the number of elements in an array

Category: Array

Syntax

DIM < n >( array- name )

DIM ( array-name , bound-n )

Arguments

n

  • specifies the dimension, in a multidimensional array, for which you want to know the number of elements. If no n value is specified, the DIM function returns the number of elements in the first dimension of the array.

array-name

  • specifies the name of an array that was previously defined in the same DATA step.

bound-n

  • specifies the dimension, in a multidimensional array, for which you want to know the number of elements. Use bound-n only when n is not specified.

Details

The DIM function returns the number of elements in a one-dimensional array or the number of elements in a specified dimension of a multidimensional array when the lower bound of the dimension is 1. Use DIM in array processing to avoid changing the upper bound of an iterative DO group each time you change the number of array elements.

Comparisons

  • DIM always returns a total count of the number of elements in an array dimension.

  • HBOUND returns the literal value of the upper bound of an array dimension.

Note: This distinction is important when the lower bound of an array dimension has a value other than 1 and the upper bound has a value other than the total number of elements in the array dimension.

Examples

Example 1: One-dimensional Array

In this example, DIM returns a value of 5.

Therefore, SAS repeats the statements in the DO loop five times. array big{5} weight sex height state city;

 do i=1 to dim(big);  more SAS statements  ;  end; 

Example 2: Multidimensional Array

This example shows two ways of specifying the DIM function for multidimensional arrays. Both methods return the same value for DIM, as shown in the table that follows the SAS code example.

 array mult{5,10,2} mult1-mult100; 

Syntax

Alternative Syntax

Value

DIM(MULT)

DIM(MULT,1)

5

DIM2(MULT)

DIM(MULT,2)

10

DIM3(MULT)

DIM(MULT,3)

2

See Also

Functions:

  • 'HBOUND Function' on page 577

  • 'LBOUND Function' on page 624

Statements:




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net