SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Processing Variables with Arrays
Creating One-Dimensional Arrays


Using the DIM Function in an Iterative DO Statement

When using DO loops to process arrays, you can also use the DIM function to specify the TO clause of the iterative DO statement. For a one-dimensional array, specify the array name as the argument for the DIM function. The function returns the number of elements in the array.


General form, DIM function:
DIM(array-name)

where array-name specifies the array.


In this example, dim(wt) returns a value of 6.
     data hrd.convert;
        set hrd.fitclass;
        array wt(6) weight1-weight6;
        do i=1 to dim(wt);
           wt(i)=wt(i)*2.2046;
        end;
     run;

By using the DIM function, you do not have to re-specify the stop value of an iterative DO statement if you change the dimension of the array.

     data hrd.convert;                data hrd.convert;
        set hrd.fitclass;                set hrd.fitclass;
        array wt(6) weight1-weight6;     array wt(10) weight1-weight10;
        do i=1 to dim(wt);              do i=1 to dim(wt);
           wt(i)=wt(i)*2.2046;              wt(i)=wt(i)*2.2046;
        end;                             end;
     run;                             run;

back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement