Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-24-2019 01:41 PM
(1015 views)

Hello,

I wrote the following code that determines the weights maximizing a ratio. These weights should be positive given the constraint on variables:

` var W{Assets_BY} >= 0 <= 0.1;`

but many of them are actually negative (admittedly small, with order E-7). However, when I rescale them so that their sum is equal to 1, they are no longer negligible with the smaller value being equal to -0.135.

```
%let byvar = grp;
proc optmodel printlevel=0;
set OBS;
num grp {OBS};
set <string> Assets;
set <num,str> GROUPS_ASSETS;
number MVC{GROUPS_ASSETS, Assets};
read data Work.MVC into Assets=[Name];
read data Work.MVC into OBS=[_N_] grp;
read data Work.MVC nomiss into GROUPS_ASSETS=[k=grp i=Name] {j in Assets} <MVC[k,i,j]=col(j)>;
set BYSET = setof {i in OBS} &byvar.[i];
num by;
set OBS_BY = {i in OBS: &byvar.[i] = by};
set Assets_BY = setof {o in OBS_BY, <(grp[o]),a> in GROUPS_ASSETS} a;
var W{Assets_BY} >= 0 <= 0.1;
impvar Denom = sqrt(sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j]);
maximize DR = log(sum{i in Assets_BY}W[i]*sqrt(MVC[by,i,i]) / Denom);
num W_sol {GROUPS_ASSETS};
do by = BYSET;
put by=;
solve;
for {i in Assets_BY} W_sol[by,i] = W[i].sol;
end;
create data Work.Weights_MD from [&byvar i] W=W_sol;
quit;
```

Thank you for any advice to obtain weights that respect the lower and upper bounds,

Best,

PS: if necessary, I will provide a small working example

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The default feasibility tolerance is 1e-6, so 1e-7 is within that tolerance. You can change the value by using the FEASTOL= option.

If you want the sum of W to be 1, it might be best to explicitly declare such a constraint. If that doesn't suffice, please share your data.

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The default feasibility tolerance is 1e-6, so 1e-7 is within that tolerance. You can change the value by using the FEASTOL= option.

If you want the sum of W to be 1, it might be best to explicitly declare such a constraint. If that doesn't suffice, please share your data.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you very much for your help 🙂

I will try to define a lower feasibility tolerance. As for the "sum of weight" constraint, I removed it because it was much longer with it, but perhaps it will be more efficient than a lower feasibility tolerance. I will perform some tests. Thank you!

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

Multiple Linear Regression in SAS

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.