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 06-18-2019 09:30 AM
(654 views)

I'm getting stuck in defining constraints and the optimization function in matrix form for proc optmodel.

Suppose these scenarios:

1) I have two vectors A and B, and my constraint is A<=B (meaning: element-wise). How can I write it without a for loop to cycle the on the elements?

2) I have two matrices A and B, and my constraint is A[:, k]' * B[: ,k] <= 0 for each k in 1..n (meaning: for each k in 1..n, take the k-th column of matrix A, transpose it, take the k-th column of matrix B, and do the scalar product between the two vectors; this number must be <=0). How can I write it with only one for loop to cycle over k?

These conditions are very easy to write e.g. in Matlab, but I find very difficult to write them in the proc optmodel.

How would you do that?

Any help appreciated,

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

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

PROC OPTMODEL uses algebraic expressions to declare such constraints:

```
var A {1..n};
var B {1..n};
con MyCon {i in 1..n}:
A[i] <= B[i];
```

```
var A {1..m, 1..n};
var B {1..m, 1..n};
con MyCon {k in 1..n}:
sum {i in 1..m} A[i,k] * B[i,k] <= 0;
```

You might also be interested in this post, which shows how to use PROC FCMP with PROC OPTMODEL to access some matrix routines.

2 REPLIES 2

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

PROC OPTMODEL uses algebraic expressions to declare such constraints:

```
var A {1..n};
var B {1..n};
con MyCon {i in 1..n}:
A[i] <= B[i];
```

```
var A {1..m, 1..n};
var B {1..m, 1..n};
con MyCon {k in 1..n}:
sum {i in 1..m} A[i,k] * B[i,k] <= 0;
```

You might also be interested in this post, which shows how to use PROC FCMP with PROC OPTMODEL to access some matrix routines.

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

Thanks a lot, it really helped!

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 16. Read more here about **why** you should contribute and **what is in it** for you!

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.