BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rohailk
Obsidian | Level 7

Hi,

I dont know why we use IMPVAR.

I have the following code

PROC OPTMODEL;
/* declare sets and parameters */
set RESOURCES = /labor metal wood/;
set PRODUCTS = /desks chairs bookcases bedframes/;
num selling_price {PRODUCTS} = [94 79 125 109];
num cost {RESOURCES} = [14 20 11];
num availability {RESOURCES} = [225 117 420];
num required {PRODUCTS, RESOURCES} =
[2 1 3
1 1 3
3 1 4
2 1 4];
/* declare variables */
var NumProd {PRODUCTS} >= 0;
impvar Revenue = sum {p in PRODUCTS}
selling_price[p] * NumProd[p];
impvar AmountUsed {r in RESOURCES} =
sum {p in PRODUCTS} NumProd[p] * required[p,r];
impvar TotalCost = sum {r in RESOURCES}
cost[r] * AmountUsed[r];
/* declare constraints */
con Usage {r in RESOURCES}:
AmountUsed[r] <= availability[r];
/* declare objective */
max NetProfit = Revenue - TotalCost;
/*print model formulation*/
expand;
/*solve the model*/
solve;
/*print parts of the model*/
print NumProd;
quit;

I have two question:

1-Please can someone tell me why are we using IMPVAR?

2- Can someone solve the above example using VAR only so that I can know the difference between VAR and IMPVAR.

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

As described here, implicit variables are useful when the same expression is needed in several places and you don't want to increase the number of explicit variables and constraints.

For your code, if you wanted to replace the first implicit variable, for example, it would look like this:

*impvar AmountUsed {r in RESOURCES} =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];
var AmountUsed {RESOURCES};
con AmountUsedCon {r in RESOURCES}: AmountUsed[r] =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];

 

View solution in original post

1 REPLY 1
RobPratt
SAS Super FREQ

As described here, implicit variables are useful when the same expression is needed in several places and you don't want to increase the number of explicit variables and constraints.

For your code, if you wanted to replace the first implicit variable, for example, it would look like this:

*impvar AmountUsed {r in RESOURCES} =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];
var AmountUsed {RESOURCES};
con AmountUsedCon {r in RESOURCES}: AmountUsed[r] =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1 reply
  • 2071 views
  • 0 likes
  • 2 in conversation