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

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-18-2010 09:42 AM

I want to know if there is any SAS/IML function which returns the row and column location of an element with a M x N or N x N Matrix.

For example, I want to know the location of the smallest element in the matrix A. I can find the element using

>>a=loc(min(A));

This returns the elements value, but not the position within the matrix.

Even when I try

>>b=ncol(min(A));

>>c=nrow(min(A));

SAS/IML only return column=1 row=1, since it still recognizes the elements as a value, separate from the Matrix.

Appreciate any help you could give.

For example, I want to know the location of the smallest element in the matrix A. I can find the element using

>>a=loc(min(A));

This returns the elements value, but not the position within the matrix.

Even when I try

>>b=ncol(min(A));

>>c=nrow(min(A));

SAS/IML only return column=1 row=1, since it still recognizes the elements as a value, separate from the Matrix.

Appreciate any help you could give.

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

05-18-2010 11:43 AM

Put the condition that you are searching for inside the LOC statement, as in

idx = loc( A = min(A) ); /* indices where A equals min(A) */

or, in general,

idx = loc( A = value ); /* indices where A equals 'value' */

The previous statements return ALL indices that satisfy the condition.

It turns out that for "index of minimum" and "index of maximum" there is a subscript reduction operator that returns the FIRST index that satisfies the condition. See

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/workmatrix_sect14.htm

idx = loc( A = min(A) ); /* indices where A equals min(A) */

or, in general,

idx = loc( A = value ); /* indices where A equals 'value' */

The previous statements return ALL indices that satisfy the condition.

It turns out that for "index of minimum" and "index of maximum" there is a subscript reduction operator that returns the FIRST index that satisfies the condition. See

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/workmatrix_sect14.htm