BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hadesmr
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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;

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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;

hadesmr
Calcite | Level 5

Thanks a lot RobPratt. It really helps. i may need to bother you again when i have more questions (high chance:))

Fisher

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

Discussion stats
  • 2 replies
  • 1525 views
  • 0 likes
  • 2 in conversation