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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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