BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
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.
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ
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

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 2770 views
  • 0 likes
  • 2 in conversation