DATA Step, Macro, Functions and more

Multidimensional Array

Reply
Contributor
Posts: 73

Multidimensional Array

Hello SAS Community,

Is it possible to create more than two dimensional arrays? Something like

array book{100, 50, 25} p1-p125000;

where each element represents location on page of a book that can be accessed by {page, row, column} terminology. For eg: p100 will point to location on page 2 row 5 column 10.

Super User
Posts: 17,912

Re: Multidimensional Array

Yes.

Contributor
Posts: 73

Re: Multidimensional Array

Thanks.

Is there any limit in theory memorywise how many dimensions can be allocated?

Super User
Posts: 17,912

Re: Multidimensional Array

I don't think so, because unless its used as _temporary_ I don't think its loaded into memory, it scans over.

An array in SAS is NOT the same as an array in C/Fortran or most other languages, it just references other variables.

SAS(R) 9.2 Language Reference: Concepts, Second Edition

Depending on what you're trying to do this may or may not be the best design method. If you want an in memory process, perhaps look at hash tables instead.

Contributor
Posts: 73

Re: Multidimensional Array

So will it be ok to use * for unspecified dimension

array book{*, 50, 25} $ 25 ;

do i=1 to dim{book}/1250;

    wordfirst=book{i,1,1};

    output;

end;

This snippet represents book{page, row, column} where each word is 25 character long at the most. It is reading first word on every page, where number of pages in undetermined and writes it to output data set.

Super User
Super User
Posts: 6,502

Re: Multidimensional Array

Short answer NO.

Your little snippet of code is missing the key information of how the words are going to get loaded into the array.

If you can explain what you are trying to do then perhaps someone can suggest a way to format that as SAS datasets.

Contributor
Posts: 73

Re: Multidimensional Array

This is theoretical situation where array is already loaded.

There are multiple ways to input data into array like initialization using parentheses or simply direct addressing:

array book{*, 50, 25} $ 25 ('The' 'brown' 'fox' 'is' 'jumping' ...); * ... represents more words ;

It is lot of typing just like datalines statement.

Ask a Question
Discussion stats
  • 6 replies
  • 275 views
  • 0 likes
  • 3 in conversation