BookmarkSubscribeRSS Feed
noobs
Calcite | Level 5

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
Calcite | Level 5

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
Calcite | Level 5

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
Calcite | Level 5

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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