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

Hello,

 

I'm trying to solve an elasticity problem in which I'm maximizing revenue such as the example presented here:

http://support.sas.com/documentation/cdl/en/ormpex/66104/HTML/default/viewer.htm#ormpex_ex21_sect009...

 

However, I'm trying to add a constraint so that the price of product A has to be the same price as the price in product B in the output. Which you'll see my attempt in the rack_rate_con constraint on the code.

 

Here is my current SAS Code:

 

/*Previous Prievious Price and Demand Data*/
data product_data;
   input product $  prev_demand prev_price;
   datalines;
Land      60  120
Trans     30  120
;
run;


/*Elasticity Data*/
data elasticity_data;
   input i $ j $ elasticity;
   datalines;
Land    Land   -0.85
Trans   Trans   -0.27
;
run;



proc optmodel;
/*   set <str> RAWS;*/
/*   num supply {RAWS};*/
/*   read data raw_material_data into RAWS=[raw] supply;*/

   set <str> PRODUCTS;
   num prev_demand {PRODUCTS};
   num prev_price {PRODUCTS};
/*   num percent {PRODUCTS, RAWS};*/
   read data product_data into PRODUCTS=[product] prev_demand prev_price;
      
   num elasticity {PRODUCTS, PRODUCTS} init 0;
   read data elasticity_data into [i j] elasticity;


 var Price {PRODUCTS} >= 0;

   var Demand {PRODUCTS} >= 0;

   
   max TotalRevenue 
      = sum {product in PRODUCTS} Price[product] * Demand[product];

   con Demand_con {i in PRODUCTS}:
      (Demand[i] - prev_demand[i]) / prev_demand[i] 
    = sum {j in PRODUCTS} elasticity[i,j] * (Price[j] - prev_price[j]) / 
      prev_price[j];


   con Price_index_con:
      sum {product in PRODUCTS} prev_demand[product] * Price[product]
   <= sum {product in PRODUCTS} prev_demand[product] * prev_price[product];

/* Attempting to add constraint to make sure the price of the two recommendations is the same*/ 
   con rack_rate_con {i in PRODUCTS}: 
     sum {PRODUCTS} Price[i] 
   = sum {j in PRODUCTS} Price[j]; 

solve with NLP / algorithm=activeset MULTISTART SEED=7888422;
print Price Demand TotalRevenue; print Price_index_con.dual; print rack_rate_con.dual;
run;

 

I do not error out, but it's not suggesting any changes. However, If I add the FEASTOL=2 option, it starts suggesting rates that are close enough to each other, but the calculated demand is way off when enabling this option.

 

If I remove the rack_rate_con constraint altogether, the calculated demand looks reasonable.

 

Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Audron
Obsidian | Level 7

I think I got it to work, and here is my new code:

 

/*Previous Prievious Price and Demand Data*/
data product_data;
   input product $  prev_demand prev_price;
   datalines;
Land      60  120
Trans     30  120
;
run;


/*Elasticity Data*/
data elasticity_data;
   input i $ elasticity;
   datalines;
Land    -0.85
Trans    -0.27
;
run;



proc optmodel;
   set <str> PRODUCTS;
 
   num prev_demand {PRODUCTS};
   num prev_price {PRODUCTS};
   read data product_data into PRODUCTS=[product] prev_demand prev_price;
   num elasticity {PRODUCTS};
   read data elasticity_data into [i] elasticity;

   var Price >= 0;
   var Demand {PRODUCTS} >= 0;


   max TotalRevenue = sum {product in PRODUCTS} Price * Demand[product];

   con Demand_con {i in PRODUCTS}:
      (Demand[i] - prev_demand[i]) / prev_demand[i]  = sum {PRODUCTS} elasticity[i] * (Price - prev_price[i]) / prev_price[i];



   solve with NLP / algorithm=activeset MULTISTART SEED=7888422;
   print Price Demand TotalRevenue; 
   print Demand_con.dual;
   expand;
RUN;

 

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

The EXPAND statement shows the following model:

Var Price[Land] >= 0                                                                           
Var Price[Trans] >= 0                                                                          
Var Demand[Land] >= 0                                                                          
Var Demand[Trans] >= 0                                                                         
Maximize TotalRevenue=Price[Land]*Demand[Land] + Price[Trans]*Demand[Trans]                    
Constraint Demand_con[Land]: 0.0166666667*Demand[Land] + 0.0070833333*Price[Land] = 1.85       
Constraint Demand_con[Trans]: 0.0333333333*Demand[Trans] + 0.00225*Price[Trans] = 1.27         
Constraint Price_index_con: 60*Price[Land] + 30*Price[Trans] <= 10800                          
Constraint rack_rate_con[Land]: Price[Land] - Price[Trans] = 0                                 
Constraint rack_rate_con[Trans]: Price[Trans] - Price[Land] = 0                                

This does seem to do what you want, but notice that the last two constraints are duplicates.  A simpler approach to ensure that both products have the same price is to not index the Price variable by product.  For example, the variable declaration would be:

   var Price >= 0;

Both approaches yield optimal objective value 10800.

Audron
Obsidian | Level 7

I think I got it to work, and here is my new code:

 

/*Previous Prievious Price and Demand Data*/
data product_data;
   input product $  prev_demand prev_price;
   datalines;
Land      60  120
Trans     30  120
;
run;


/*Elasticity Data*/
data elasticity_data;
   input i $ elasticity;
   datalines;
Land    -0.85
Trans    -0.27
;
run;



proc optmodel;
   set <str> PRODUCTS;
 
   num prev_demand {PRODUCTS};
   num prev_price {PRODUCTS};
   read data product_data into PRODUCTS=[product] prev_demand prev_price;
   num elasticity {PRODUCTS};
   read data elasticity_data into [i] elasticity;

   var Price >= 0;
   var Demand {PRODUCTS} >= 0;


   max TotalRevenue = sum {product in PRODUCTS} Price * Demand[product];

   con Demand_con {i in PRODUCTS}:
      (Demand[i] - prev_demand[i]) / prev_demand[i]  = sum {PRODUCTS} elasticity[i] * (Price - prev_price[i]) / prev_price[i];



   solve with NLP / algorithm=activeset MULTISTART SEED=7888422;
   print Price Demand TotalRevenue; 
   print Demand_con.dual;
   expand;
RUN;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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