BookmarkSubscribeRSS Feed
AAZ
Fluorite | Level 6 AAZ
Fluorite | Level 6

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. 

3 REPLIES 3
RobPratt
SAS Super FREQ

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

 

AAZ
Fluorite | Level 6 AAZ
Fluorite | Level 6

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

RobPratt
SAS Super FREQ

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1027 views
  • 0 likes
  • 2 in conversation