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
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.
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.
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!
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.