Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Copying values to an array

Reply
Occasional Contributor AAZ
Occasional Contributor
Posts: 18

Copying values to an array

Hi, 

 

I have an array of values  

"number Quantity{Item}=[0 0 30 40 50 0 60 70]" and want to assign these values to another array Quantity2 and change the index to -2  so  it should equal [30 40 50 0 60 70 0 0]. How to achive that with optmodel. 

SAS Employee
Posts: 447

Re: Copying values to an array

[ Edited ]

Here's one way:

 

proc optmodel;
   set Item = 0..7;
   number Quantity{Item}=[0 0 30 40 50 0 60 70];
   number Quantity2{i in Item} = Quantity[mod(i+2,8)];
   print Quantity Quantity2;
quit;

SAS Output

[1] Quantity Quantity2
0 0 30
1 0 40
2 30 50
3 40 0
4 50 60
5 0 70
6 60 0
7 70 0

 

Occasional Contributor AAZ
Occasional Contributor
Posts: 18

Re: Copying values to an array

Thanks Rob, 

what I am trying to achieve is to take the optimized quantity  "Quantity", offset it x places, and give this output (Quantity) as an input to Quantity2, where I will run another optimization model on it Quantity2.  " I assume I can have both in the same program?"

So Quantity is not actually a number it's a variable and I receive the following error when saying that  

Quantity2{i in Item} = Quantity[mod(i+2,8)];

 

as Quantity is a var  and Quantity2 is number 

 

537-782 the value of parameter "Quantity2" depends on a variable

SAS Employee
Posts: 447

Re: Copying values to an array

If Quantity is a variable, then it sounds like you want to declare Quantity2 as an implicit variable (by using the IMPVAR statement).

Ask a Question
Discussion stats
  • 3 replies
  • 147 views
  • 0 likes
  • 2 in conversation