BookmarkSubscribeRSS Feed
noobs
Fluorite | Level 6

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.

6 REPLIES 6
Reeza
Super User

Yes.

noobs
Fluorite | Level 6

Thanks.

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

Reeza
Super User

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.

noobs
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

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.

noobs
Fluorite | Level 6

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1920 views
  • 0 likes
  • 3 in conversation