BookmarkSubscribeRSS Feed
Crubal
Quartz | Level 8

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.

6 REPLIES 6
RobPratt
SAS Super FREQ

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.

Crubal
Quartz | Level 8

Thank you Rob!

May I ask you if not rename or reindex the variables, how could I write them?

Thank you!

RobPratt
SAS Super FREQ

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.

Crubal
Quartz | Level 8

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;

RobPratt
SAS Super FREQ

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.

Crubal
Quartz | Level 8

got it~!

Thanks

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