Hi,
On SAS proc optmodel,
If I ahve already defined raw_quantity_1[j,m] and raw_quantity1_1[m,q], they are in different constraints.
The relationship between them is sum {q in Price_intervals} raw_quantity1_1[m,q] = raw_quantity_1[1,m]
and sum {q in Price_intervals} raw_quantity2_1[m,q] = raw_quantity_1[2,m]
and sum {q in Price_intervals} raw_quantity3_1[m,q] = raw_quantity_1[3,m]
But raw_quantity_1[1,m], raw_quantity_1[2,m] and raw_quantity_1[3,m] should all be expressed as raw_quantity_1[j,m]
Is there any constraint that I can define like that?
Thanks and sorry I am not able to upload any file.
I would recommend not hard-coding the numbers into your variable names. If you rename and reindex your variables, you can then express the desired constraints compactly as:
con Mycon {j in JSET, m in MSET}:
sum {q in Price_intervals} raw_quantity_jmq[j,m,q] = raw_quantity_jm[j,m];
This approach provides better separation between model and data, shortens the code, and reduces the likelihood of copy-and-paste errors.
Thank you Rob!
May I ask you if not rename or reindex the variables, how could I write them?
Thank you!
If you want to keep the original variable names and indices, you could use the SAS macro language, like this:
%do j = 1 %to 3;
con Mycon&j {m in MSET}:
sum {q in Price_intervals} raw_quantity&j._1[m,q] = raw_quantity_1[&j,m];
%end;
To use this approach, you would need to wrap at least this part in a macro (using %macro and %mend). But my first recommendedation is simpler and more efficient, especially if you have a lot more than three values of j.
Hi Rob!
Thanks!
I just wanna try the first way, like below:
%macro cons1;
%do j = 1 %to 3;
con Mycon1&j {j in SUPPLIERS, m in RAW_MATERIALS}:
SUM {q in PRICE_INTERVALS} raw_quantity&j_1[m,q] = raw_quantity_1[&j,m];
%end;
%mend cons1;
%cons1;
With the error message:
! raw_quantity&j_1[m,q] = raw_quantity_1[&j,m];
-
22
76
WARNING: Apparent symbolic reference J_1 not resolved.
ERROR 22-322: Syntax error, expecting one of the following: !!, (, *, **, +, -, .., /, <=, <>, =, ><,
>=, BY, CROSS, DIFF, ELSE, INTER, SYMDIFF, TO, UNION, [, ^, ||.
ERROR 76-322: Syntax error, statement will be ignored.
%cons1;
You need the dot after the &j (as in my code). Also, you should not use j in SUPPLIERS as a constraint index if you are using the macro loop with j.
got it~!
Thanks
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.