BookmarkSubscribeRSS Feed
milts
Pyrite | Level 9

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!

8 REPLIES 8
gergely_batho
SAS Employee

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.

milts
Pyrite | Level 9

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.

Ksharp
Super User

No way for SAS, But JAVA can do that .

milts
Pyrite | Level 9

So true. Makes me miss Java because of this requirement.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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,

milts
Pyrite | Level 9

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Reeza
Super User

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.

sas-innovate-2024.png

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.

 

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
  • 8 replies
  • 1106 views
  • 0 likes
  • 5 in conversation