SAS Optimization, and SAS Simulation Studio

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2012 12:16 PM

Hi all,

Need your help again. I need to declare an impvar g to do the following calculation: if i = 1 then g[1]=0 else g*=s *f[i-1]+s*g[i-1]; When i run the code, the log says "The Symbol 'g' is unknown". It looks like i can't reference g[i-1] on the same line when declaring g as impvar (because when i deleted s*g[i-1], the code works perfectly). *

Can someone help me fix it? It did work in the Proc NLP.

Thanks a lot. really appreciate it.

HY

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

2420611 7.53

2338870 7.63

2268830 7.74

2462173 7.74

10775045 7.8

2834195 7.75

2666271 7.55

2734586 7.65

11722258 7.6

2366007 7.71

;

run;

%let xx = .1;

proc optmodel;

set w;

number org{w};

number dep{w};

var s{w} >= 0 <= .8 init 1;

impvar f {i in w} = s* * (1 - &xx);*

**impvar g {i in w} = if i = 1 then 0 ****else g = s*f[i-1] + s*g[i-1];**

impvar ads {i in w} = g* * org ;*

read data work.cor into w = [_n_] org dep;

max correlation = (card(w)*sum{i in w}(ads**dep ) - (sum{i in w}(ads)) * (sum{i in w}(dep)))*

/ (sqrt(card(w)*sum{i in w}(ads^2) - (sum{i in w}(ads))^2) * sqrt(card(w)*sum{i in w}(dep^2) - (sum{i in w}(dep))^2));

con c {i in w diff {card(w)}: mod(i,8) ne 0}: s = s[i+1];

solve;

print s f g ads correlation;

quit;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hadesmr

04-02-2012 12:33 PM

Recursive IMPVAR is not supported until the next release of SAS/OR, due out later this year. The correct syntax will be:

impvar g {i in w} = if i = 1 then 0 else s**f[i-1] + s *g[i-1];*

Until then, you can instead use an explicit variable and constraint.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobPratt

04-02-2012 01:13 PM

Hi RobPratt,

Thanks for letting me know and correcting the code.

Can you show me how to use an explicit variable and constraint to acheive the same result (impvar g {i in w} = if i = 1 then 0 else s**f[i-1] + s *g[i-1] before the newer verson of SAS is released later this year?*

Much appreciative!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobPratt

04-02-2012 02:13 PM

Looks like this code works. What do you think RobPratt? Anyway to make it moer efficient?

And what's the difference between declaring g as VAR and IMPVAR? Thanks!

var g {i in w} >= 0 init 1;

........

.......

con gg {i in w: i>=2}: g* = s1 *f[i-1] + s1*g[i-1];*

** **

** **

** **

** **

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hadesmr

04-02-2012 02:50 PM

You almost got it, but you still need to force g[1] = 0. The following works:

con gg {i in w}: g* = if i = 1 then 0 else s1 *f[i-1] + s1*g[i-1];*

Or you could keep your version and then also include:

fix g[1] = 0;

When you use IMPVAR, PROC OPTMODEL does the algebraic substitution for you, and the solver does not see an explicit variable or constraint.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobPratt

04-02-2012 04:07 PM

Hi RobPratt,

I just sent you a private discussion because there is something i better not to disclose in the public forum. Thanks for your understanding.