Hi Rob, I have given a simple example of what I am trying to do. In the following macro, x1 and x2 are the decision variables and SSE is the objective function that is to be minimized. (The one I have given is fairly simple and the actual code has far more calculations to arrive at SSE). SSE = f(x1, x2) is the objective function but it is not possible to write out the calculation since calculations are not straight forward. data test; input hours actualRisk; datalines; 1.2 0.05 0.3 0.008 10 0.5 7 0.09 2.9 0.15 3 0.1 7.5 0.25 8 0.20 3.5 0.1 1.7 0.15 ; run; %MACRO generateSSE(x1, x2); DATA test; SET test; calculatedRisk = CDF('WEIBULL',hours,&x1,&x2); RUN; data test; set test; squaredErrors = (actualRisk - calculatedRisk)*(actualRisk - calculatedRisk); run; PROC SQL NOPRINT; SELECT SUM(squaredErrors) into :SSE FROM test; QUIT; %PUT &SSE; %MEND generateSSE; %generateSSE(1,2); Could you please let me know how to pass generateSSE to an optimizer to find the values of x1 and x2 that minimizes SSE? I have implemented the same using the optim function in R and have given the code below: hours <- c(1.2, 0.3, 10, 7, 2.9, 3, 7.5, 8, 3.5, 1.7) actualRisk <- c(0.05, 0.008, 0.5, 0.09, 0.15, 0.1, 0.25, 0.20, 0.1, 0.15) test <- data.frame(hours = hours, actualRisk = actualRisk) generateSSE <- function(x) { test$calculatedRisk <- dweibull(test$hours, shape = x[1], scale = x[2]) test$squaredErrors <- (test$actualRisk - test$calculatedRisk)^2 return(sum(test$squaredErrors)) } optout=optim(c(1,2), generateSSE, NULL, method = "L-BFGS-B", lower=rep(0.4,0.05), upper=rep(8, 1000),control=list(reltol=0.01)) I would like to implement a similar solution in SAS. Thank you. Ravi
... View more