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

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

Posted 11-07-2014 12:41 PM
(1276 views)

I have a constraint which sums the nonzero elements of a sparse matrix. To do this, I am using the SLICE expression, so my constraint reads

like this:

con test{t in ASC}:sum{u in slice(<t,*>,Map)}y__>=0;__

Here 'Map' is a sparse matrix, with 2 mapped variables - ASC and UIN, i.e. 'Map' contains all eligible pairs of ASC and UIN.

The constraint should work like this: For each element 't' of ASC, it should check whether 't' has a corresponding value 'u' for UIN variable. If there is, then it adds y for that row.

However, when I run this constraint, I get a "Constraint is empty" error.

What am I doing wrong here/is there a better way of doing this?

3 REPLIES 3

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

You can write this more compactly by using an "implicit" slice:

con test{t in ASC}: sum{<(t),u> in Map} y__ >= 0;__

See this doc example for more discussion:

SAS/OR(R) 13.2 User's Guide: Mathematical Programming Examples

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

Thanks for the link.

Somehow the constraint you gave doesn't seem to work(again a "Constraint is empty" error). But the following constraint worked(I got it from the link you gave):

con test{t in ASC}:sum{u in UIN:<u,t> in Map}y__>=0;__

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

Your latest version is not equivalent to the other two. Instead, it should be:

con test{t in ASC}:sum{u in UIN:<t,u> in Map}y__>=0;__

Also, the "Constraint is empty" message is only a NOTE and not an ERROR. If you use the EXPAND statement, you will see that the constraint is 0 >= 0 because the sum is empty. If you really want to avoid generating these constraints, you can use a logical condition:

con test{t in ASC: card(slice(<t,*>,Map)) > 0}:sum{u in slice(<t,*>,Map)}y__>=0;__

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