Hi
May I ask for your help with reading 3D array into the optmodel procedure?
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?
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.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.