Given that I have to create a multidimensional array of the below:
silo1 - storage 1, storage 2, storage 3
silo2 - storage 4, storage 5, storage 6, storage 7
If I create an array arrsilo [2,4] storage1- storage7 will get an error since it expects 8 variables. Is there a way I can create the array that will allow me to have the array have only 3 columns for row 1 then 4 columns for row 2?
Any other ways would greatly be appreciated. Thank you!
No. 2 dimensional arrays are n1 x n2 tables.
But this is valid:
array arrsilo [2,4] storage1- storage3 dummy storage4 - storage7;
drop dummy;
Or you can use associative arrays: hash object.
This is my current workaround although I was thinking of a more appropriate way.
How do you implement such has object? Greatly appreciate if you can give an example.
No way for SAS, But JAVA can do that .
So true. Makes me miss Java because of this requirement.
Not sure what your problem is or what you are trying to achieve as you already have the array:
I assume you have a table like:
STORAGE1 STORAGE2...STORAGE7. Now that in itself is an array{7} of variables named storage. If you then want these in two rows your end product will look like:
ID VAR1 VAR2 VAR3 VAR4
silo1 - storage 1, storage 2, storage 3
silo2 - storage 4, storage 5, storage 6, storage 7
All an array is in terms of SAS is a convinient reference to variables in your dataset, so in the above VAR{x} is the array and refers to VAR1, VAR2 etc. You could have an array refence to COL1, ABC1, EDC1 etc,
If I'll be using a normal array I won't be able to identify how many storages I have for each silo based on my example fields. Because I would be creating a different logic/treatment depending on the number of silos.
Simple:
ID VAR1 VAR2 VAR3 VAR4 No_Storage
silo1 storage 1, storage 2, storage 3 3
silo2 storage 4, storage 5, storage 6, storage 7 4
I agree with Reeza, clarify what you are trying to do. Different technologies approach problems in differing ways.
Perhaps restate your actual issue then and a more appropriate SAS solution can be offered.
Because SAS processes data line by line rather than loading the entire dataset into memory means it operates differently, sometimes that's good and sometimes that's bad. But it does mean the best way to handle a certain scenario may differ from a memory based language.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.