BookmarkSubscribeRSS Feed
Decay2020
Fluorite | Level 6

Hi All,

I have below 3 inputs, one is data "Have" and two values "value1" and "Value2". I want to arrive at "final data want" (as described below) such that sum product of col2 and col3 equals a constant by changing value1 and keeping value2 same. 


data have ;
infile cards  ;
input col1;
cards;
1
2
3
4
5
6
7

;
run;

 

value1 = -4.56266639

value2 = 0.28179071

 

I want to calculate col2 as value1 + (value2*col1)

and col3 as EXP(col2)/(1+EXP(col2)) such that sum product of col2 and col3 equals 0.036 by changing the value1. 

 

Final data want:

col1col2col3
1-4.280880.013642
2-3.999080.018002
3-3.717290.023723
4-3.43550.031204
5-3.153710.040945
6-2.871920.053559
7-2.590130.069776

 

3 REPLIES 3
RobPratt
SAS Super FREQ

Here's one way to do it:

 

%let value1 = -4.56266639;
%let value2 = 0.28179071;

proc optmodel;
   set OBS;
   num col1 {OBS};
   read data have into OBS=[_N_] col1;

   var value1;
   num value2 = &value2;
   impvar col2 {i in OBS} = value1 + value2 * col1[i];
   impvar col3 {i in OBS} = EXP(col2[i]) / (1 + EXP(col2[i]));
   con SumProduct:
      sum {i in OBS} col2[i] * col3[i] = 0.036;

/*   fix value1 = &value1;*/

   solve noobj;
   print value1;
   print col1 col2 col3;
   create data want(drop=i) from [i] col1 col2 col3;
quit;

On my machine, I get:

 

value1
-1.2786

[1] col1 col2 col3
1 1 -0.99685 0.26956
2 2 -0.71506 0.32848
3 3 -0.43327 0.39335
4 4 -0.15147 0.46220
5 5 0.13032 0.53253
6 6 0.41211 0.60159
7 7 0.69390 0.66683

 

To recover the values you showed, you can uncomment the FIX statement to force the solver to return that specific solution:

value1
-4.5627

[1] col1 col2 col3
1 1 -4.2809 0.013642
2 2 -3.9991 0.018002
3 3 -3.7173 0.023723
4 4 -3.4355 0.031204
5 5 -3.1537 0.040945
6 6 -2.8719 0.053559
7 7 -2.5901 0.069776

 

But that solution does not satisfy the equality constraint because the resulting SumProduct is -0.789 instead of 0.036.

Decay2020
Fluorite | Level 6
Thank you for you quick turn around.
I apologize I made an error in the query.
value1 = -4.60875
After optimization it should come as -4.56267, but we start with Value1 as -4.60875
RobPratt
SAS Super FREQ

It turns out that value1 = -1.2786 is the unique feasible solution.  Here is a portion of the plot of SumProduct as a function of value1, with a horizontal reference line at 0.036:

sascommunities020422.png

You can initialize the solver at &value1 by changing the VAR statement:

var value1 init &value1;

But initial values to the left of the minimum at about value1 = -2.6 are likely to lead the solver astray.