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.
Yes.
Thanks.
Is there any limit in theory memorywise how many dimensions can be allocated?
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.
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.
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.