Hi guys,
Need your help. i am trying to maximize two variables' (dep and org*s) correlaton by changing the var (0<s<0.8). The below program (1st) works fine when i put [org*s] in the correlation formula. However, if i create a new variable, ads = org*s, the program doesn't work anymore. The reason i need to create a new variable ads is that there will be more calculations involved and i don't want to write an extreme long function in max procesure. i need to break out the long function to several pieces. i remember the old Proc NLP can do it.
This may be a very naiive question but do need your help. thx. Here are the two programs. Again, the 2nd doesn't work and i don't know how to fix it.
Thanks again!
Fisher
data cor;
input org dep;
cards;
11785895 7.42
2335492 7.58
2345245 7.58
2392912 7.53
12755890 7.63
2918402 7.67
2773183 7.68
2824198 7.65
12263433 7.53
;
run;
* program 1 that works;
proc optmodel;
set w;
number org{w};
number ads{w};
number dep{w};
var s{w} >= 0 <= .8 init 1;
read data cor into w = [_n_] org dep;
max correlation = (10*sum{i in w}((org*s)*dep) - (sum{i in w}((org*s))) * (sum{i in w}(dep)))
/ (sqrt(10*sum{i in w}((org*s)^2) - (sum{i in w}((org*s)))^2) * sqrt(10*sum{i in w}(dep^2) - (sum{i in w}(dep))^2));
solve;
print s correlation;
quit;
* program 2 that doesn't work;
proc optmodel;
set w;
number org{w};
number ads{w};
number dep{w};
var s{w} >= 0 <= .8 init 1;
read data cor into w = [_n_] org dep;
for {i in w} ads = org * s;
max correlation = (10*sum{i in w}(ads*dep) - (sum{i in w}(ads)) * (sum{i in w}(dep)))
/ (sqrt(10*sum{i in w}(ads^2) - (sum{i in w}(ads))^2) * sqrt(10*sum{i in w}(dep^2) - (sum{i in w}(dep))^2));
solve;
print s correlation;
quit;
In program 2, you have declared ads as a numeric parameter, so the resulting objective is constant. Instead, you should declare ads as an implicit variable (and omit the FOR loop) as follows:
impvar ads {i in w} = org * s;
In program 2, you have declared ads as a numeric parameter, so the resulting objective is constant. Instead, you should declare ads as an implicit variable (and omit the FOR loop) as follows:
impvar ads {i in w} = org * s;
Thanks a lot RobPratt. It really helps. i may need to bother you again when i have more questions (high chance:))
Fisher
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.