Obsidian | Level 7

## Read Data From 3D Array

Hi

I have data with structure of different branches (rows) selling cars in different variants:

``````data selling;
input branch \$ Car01_variant01 Car01_variant02 Car01_variant03 Car02_variant01 Car02_variant02 Car02_variant03;
datalines;
AAA 100 101 102 210 220 230
BBB 104 105 106 240 250 260
CCC 107 108 109 270 280 290
;``````

Can I read this table to the optmodel to I can access it 3D array such as: selling[branch, car, variant]?

In the documentation, there is only examples of different "variants" having as another column with the a separate index, such as:

```data selling;
input branch \$ variant Car01 Car01 Car01;
datalines;
AAA 1 100 101 102
BBB 1 104 105 106
CCC 1 107 108 109
AAA 2 ...
...
;```

Do I need to transform the original table, or is there a way to read the complete 3D array in my structure?

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: Read Data From 3D Array

Here's one way:

``````proc optmodel;
set <str> BRANCHES;
set CARS = /'01' '02'/;
set VARIANTS = /'01' '02' '03'/;
num selling {BRANCHES, CARS, VARIANTS};
read data selling into BRANCHES=[branch] {c in CARS, v in VARIANTS} <selling[branch,c,v]=col('Car'||c||'_variant'||v)>;
print selling;
quit;``````

Alternatively, you can read CARS and VARIANTS from other data sets rather than hard-coding their values in the SET statements.

2 REPLIES 2
SAS Super FREQ

## Re: Read Data From 3D Array

Here's one way:

``````proc optmodel;
set <str> BRANCHES;
set CARS = /'01' '02'/;
set VARIANTS = /'01' '02' '03'/;
num selling {BRANCHES, CARS, VARIANTS};
read data selling into BRANCHES=[branch] {c in CARS, v in VARIANTS} <selling[branch,c,v]=col('Car'||c||'_variant'||v)>;
print selling;
quit;``````

Alternatively, you can read CARS and VARIANTS from other data sets rather than hard-coding their values in the SET statements.

Obsidian | Level 7

## Re: Read Data From 3D Array

Thank you a lot, it works (including the reading values to both sets).
Discussion stats
• 2 replies
• 286 views
• 0 likes
• 2 in conversation