Prev: PROC GLM ERROR
Next: %do ind=a %to z; in Macro
From: JW on 11 Aug 2010 19:43 This will probably be considered part of a few Univariate Optimisation Questions. Unfortunately my companies SAS licence does not include Enterprise Miner or similar. I am trying to understand how I can implement a recursive algorthim using Base SAS. I have done a great deal of reading (Customise BAse SAS Implemented solvers being a good start). I have a function derived from a logistic regression FX = 3  0.2*log(x)  0.35*x/100 + 0.14*Max(age25) x here is a price of the good and I calculate the probability of purchase e(FX)/ (1+e(FX)) and an Expected Profit. I now with to calculate the point where the Expected Profit is maximized. Now I can do this easily in Excel using the solver function, however I wish to use SAS to do this somehow and then be able to extend it for multiple profiles of age. Unfortunately my attempts to extend my understanding of Macro's has thus far been less than successful. I have come across Brent's method which I believe is suitable for this type of problem. I have written the following based on what I thought (generously relying on the above paper using the secant method) may just get me there (however it doesn't work). It is perhaps a sign my thought process isn't right. This attempts to translate Brent's Method from Maxima & Fortran to SAS based on what I found on the internet (www.netlib.org/go/ zeroin.fmin.f). %macro zBrent(eqtn,x1,x2,eps); *%local = root; %let ITMAX = 100; %let eps = 3.0E8; %let FX = 3 + 0.20*log(x)+0.35*(x)/100 +0.14*(Max(age16,0)); %let FXH = 3 + 0.20*log(x+0.01)+0.35*(x+0.01)/100 +0.14*(Max(age16,0));16,0)); %let ELAS = ((FXHFX)/0.01)*(x)+1+exp(FX); (This being the elasticity or 1st derivative of my Profit Function in a generic form usually you would set this to 0 to maximize Profit). %let eqtn2=%scan(&eqtn,1,"="); %let eqtn3=%scan(&eqtn,2,"="); %let eqt=%str(y=&eqtn2&eqtn3;); data OPT_Trial; flag =0; x= &x1; &eqt; y1=y; x = &x2; &eqt; y2=y; x = &x2; &eqt; y3=y; if y1>0 and y2>0 then do; put "No root within these borders"; end; else if y1<0 and y2<0 then do; put "No root within these borders"; end; else do until (flag =1); do j = 1 to ITMAX; if y2 > 0 and y3>0 then do; x5=x4=x2x1; end; else if y2<0 and y3<0 then do; x5=x4=x2x1; end; else if abs(y3) < abs(y2) then do; x1 = x2; x2 = x3; x3 = x1; y1 = y2; y2 = y3; y3 = y1; end; else if abs(y3) > abs(y2) then do; tol1 = 2*EPS*abs(y2) + 0.5*tol; xm = 0.5*(x3x2); if abs(xm) <= tol1 then root = x2; if y2 = 0 then root =x2; end; if abs(x5) >= tol1 and abs(y1)> abs (y2) then do s = y2/y1; if x1 =x3 then do; p = 2*xm*s; q = 1s; end; else if x1 ne x3 then do; q = y1/y3; r=y2/y3; p = s*(2*xm*q*(qr)(ba)*(r1)); q = (q1)*(r1)*(s1); end; if p < 0 then do p = p; end; if p >0 then do; q = q; p =abs(p); min1 = 3*xm*qabs(tol1*q); min2 = abs(e*q); if 2*p < min1 then do; e=d; d=p/q; end; if p < Min2 then do; e=d; d=p/q; end; else do; d=xm; e=d; end; if abs(x5) < tol1 and abs(y1)> abs (y2) then do; d=xm; e=d; end; if abs(x5) >= tol1 and abs(y1)=< abs (y2) then do; d=xm; e=d; end; if abs(x5) < tol1 and abs(y1)=< abs (y2) then do; d=xm; e=d; end; x1 = x2; y1 = y2; if abs(x4) > tol1) then do; x2=x2+x4; x = &x2; y2=y; end; if abs(x4) <= tol1) then do; x2 = &eqt else b = b+tol1; x = &x2; y2=y; end; end; run; %mend zBrent(ELAS=0,1,1000000,eps); I wanted to find out whether any other SAS users have experience with this type of problem and whether they had solutions. I don't believe there is any hurry to upgrade our license in case this is basic thing in Enterprise Miner or other SAS addon so I am restricted to Enterprise 4.2 functions or code. SAS Techncial help wasn't that useful recommending PROC Loess which from what I understand is an alternative regression function. With regards

Pages: 1 Prev: PROC GLM ERROR Next: %do ind=a %to z; in Macro 