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.
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 |
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
If Quantity is a variable, then it sounds like you want to declare Quantity2 as an implicit variable (by using the IMPVAR statement).
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.