Thursday, October 31, 2013

MULTIDIMENSIONAL ARRAY

What are Multidimensional Arrays?

Definition: It is defined by specifying number of elements in each dimension separated by comma in {row, column} format.
         array book{100, 5} $ p1-p500;
This array represents 100 pages, each containing 5 paragraphs.


How do I access elements in multidimensional array?

The indices are used wisely to access specified element. Generally, iterative DO loops will do the job.

data publish.collection(drop=i j k);
     array book{100, 50, 25} $ 25 p1-p125000 ('This' 'is' 'story'      'about' 'how' 'SAS' 'was' 'born' 'and' 'how' 'it' 'is'            'grown' 'into' 'a' 'stable' 'statistical' 'analysis'              'software' 'that' 'is' 'robust' 'and' 'scalable' 'in'            'nature' ); 
     array page{5000, 25} $ 25 p1-p125000;
     do k=1 to 100;
        do i=1 to 50;
           do j=1 to 25;
              page{i+(50*(k-i)),j}=book{k,i,j}; 
           end;
        end;
     end;
run;

The snippet above reads three dimensional array and saves it as two-dimensional array.

No comments:

Post a Comment