BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
asasgdsfa
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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.

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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.

asasgdsfa
Obsidian | Level 7
Thank you a lot, it works (including the reading values to both sets).

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

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.

Discussion stats
  • 2 replies
  • 527 views
  • 0 likes
  • 2 in conversation