BookmarkSubscribeRSS Feed
OceanDream
Fluorite | Level 6

I am using the following code to solve two unknown variables (T and delta) with two equations. If I do not use "bounds t>1" AND "optimize" option, it gives me value of T close to zero to all the observations. However, if I add these two codes, the results for all observations are 1.01 for T. I checked proc model code with simple quadratic equation to get only negative results. It worked fine. Anyone could please help me? What is wrong with my current code for this more complex equations??? I am in urgent need to solve this. Please help!!!

 

Additional information: I got the following information when running the code. It seems that the code did not even iterate once to solve the equations and gave error of zero?? That does not seem right.

 

NOTE: Optimal.
NOTE: Objective = 0.4636390687.
NOTE: The NLP solver is called.
NOTE: The Interior Point algorithm is used.
Objective Optimality
Iter    Value             Infeasibility      Error
0      0.49897143         0                  0

 

"proc model data=HAVE noprint out=NEED;
bounds t>1;
eq.one = (1-PD) - (probnorm((-log(PD)-(s - 0.5*(delta*delta))*T)/(delta*sqrt(T)))
-PD*exp(s*T)* probnorm((-log(PD)-(s - 0.5*(delta*delta))*T)/(delta*sqrt(T))- delta*sqrt(T)));
eq.two = delta_E*(1-PD) - delta*probnorm((-log(PD)-(s - 0.5*(delta*delta))*T)/(delta*sqrt(T)));
solve delta T /optimize solveprint ;
id companyid date pd s delta_e;
run;"

10 REPLIES 10
RobPratt
SAS Super FREQ

PROC MODEL is part of SAS/ETS, and I see that you have already posted in the SAS Forecasting and Econometrics community.  You could also use PROC OPTMODEL to solve your equations.  Can you please share your data?

OceanDream
Fluorite | Level 6

Hi Rob,

 

Thank you for your reply. Attached is my data. I could not attach my file to the reply. It says " the contents of the attachment doesn't match its file type". Do you know what is wrong? If you don't mind, I can email you my data. Thank you so much for your help!!

 

"proc model data=bl.decomp5 noprint out=decomp6;
endo delta T;
bounds T>0.1;
eq.one = (1-PD) - (probnorm((-log(PD)-(s - 0.5*(delta*delta))*T)/(delta*sqrt(T)))
-PD*exp(s*T)* probnorm((-log(PD)-(s - 0.5*(delta*delta))*T)/(delta*sqrt(T))- delta*sqrt(T)));
eq.two = delta_E*(1-PD) - delta*probnorm((-log(PD)-(s - 0.5*(delta*delta))*T)/(delta*sqrt(T)));
solve delta T /optimize solveprint ;
id gvkey dealactivedate facilityid pd s delta_e beta;
run;"

 

RobPratt
SAS Super FREQ

Please try to attach a CSV or ZIP file instead.

OceanDream
Fluorite | Level 6

Hi Rob,

Please see attached dataset. Thanks again for your help!

RobPratt
SAS Super FREQ

Is beta supposed to be used anywhere?

OceanDream
Fluorite | Level 6

Thanks for checking it, Rob!

No. For my question, beta is not needed.

Did you find anything wrong with my data or the code?

 

RobPratt
SAS Super FREQ

I don't see the same behavior in the latest release (SAS 9.4M5).  I get various values for T, not all 1.01.  What version are you running?

 

When I add the OUTOBJVALS option, I see that the sum of squared errors is positive, meaning that the equations are not satisfied exactly.  Do you know that there is always a solution with zero error?

 

Do you know other bounds on delta and T besides T > 0.1 (or did you want T > 1)?

 

You might also want to specify a good initial solution.

 

Here is a way to minimize the sum of squared errors for the same equations with PROC OPTMODEL in SAS/OR:

proc optmodel printlevel=0;
   set OBS;
   str gvkey {OBS};
   num dealactivedate {OBS}, facilityid {OBS}, pd {OBS}, s {OBS}, delta_e {OBS}, beta {OBS};   
   read data decomp5 into OBS=[_N_] gvkey dealactivedate facilityid pd s delta_e beta;   

   num pd_this, s_this, delta_e_this;
   var delta init 1;
   var T >= 0.1 <= 9 init 1;
   var error {1..2};
   min sse = sum {i in 1..2} error[i]^2;
   con eqone: error[1] = (1-pd_this) - (probnorm((-log(pd_this)-(s_this - 0.5*(delta*delta))*T)/(delta*sqrt(T)))
      -pd_this*exp(s_this*T)* probnorm((-log(pd_this)-(s_this - 0.5*(delta*delta))*T)/(delta*sqrt(T))- delta*sqrt(T)));
   con eqtwo: error[2] = delta_e_this*(1-pd_this) - delta*probnorm((-log(pd_this)-(s_this - 0.5*(delta*delta))*T)/(delta*sqrt(T)));

   num delta_sol {OBS}, T_sol {OBS}, obj {OBS};
   option nonotes;
   cofor {i in OBS} do;
      put i=;
      pd_this = pd[i];
      s_this = s[i];
      delta_e_this = delta_e[i];
      solve with nlp / ms;
      delta_sol[i] = delta.sol;
      T_sol[i] = T.sol;
      obj[i] = _OBJ_.sol;
   end;
   option notes;
   create data optmodel_out from [i] gvkey dealactivedate facilityid pd s delta_e beta delta=delta_sol T=T_sol obj;
quit;

The upper bound of 9 on T is to prevent overflow in the exponential function.

OceanDream
Fluorite | Level 6

Hi Rob,

 

Thank you so much for you response. I did not get all values of 1.01 for T, but most of them are, which is still problematic. Did you get different values for each observations or the variation is not that much? I think my SAS version is 9.3..

 

I do not expect the solutions are always with zero error.

I only need to bound T greater than one, nothing else.

 

I have been running the code PROC OPTMODEL that you wrote for hours and it is still running. Is that what also happens to you?

RobPratt
SAS Super FREQ

I got a wide variety of T values, but none of them had zero error.

 

I ran on a busy 100-node grid, and it took 12 minutes.  You can speed things up but might find worse solutions by omitting the multistart option.  That is, replace...

solve with nlp / ms;

...with...

solve;

But I would also recommend upgrading.  The last SAS 9.3 release came out in 2012, and the subsequent releases all contain performance improvements.

OceanDream
Fluorite | Level 6

My school only provides 9.3 version of SAS.

If it is not too much to ask, could you share me with the results from running PROC MODEL using your 9.4 version?

 

I replaced 

solve with nlp / ms;

with  

solve;

using PROC OPTMODEL, but the values for T  seem reasonable, but most values for delta are one, which is not reasonable...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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