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

01-20-2012 11:17 AM

Hi, there:

I wonder how I should do it with SAS/IML.

Imagine x is a m*1 vector and I want to pick up some values from the specified positions defined by another vector, idx. For example, idx={ 2,3,7,5,10,2,7}. I write a line as:

zz=x[idx,];

zz is supposed to be a 7*1 vector whose values are from the values in corresponding positions in x, according to the index vector idx_k.

Unfortunately, the last line does not seem to be consistent with SAS/IML grammar. If we want to re-order a matrix based on an index defined by another matrix, how should we do it?

I do find some example related to my question, but I find it difficult to interpret:

In a sample code on how to use the rank function:

x={2 2 1 0 5}; /*value x

b=x; /*value b from x

x[,rank(x)]=b;

It is difficult to understand the last line. does it revalue x? If so, can just write z[,rank(x)]=b, while z is undefined matrix or a 1*m matrix with m>=5 or can I write x[,rank(x)]=x?

Thanks.

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

01-20-2012 11:32 AM

I think you can use the ideas in this blog post: http://blogs.sas.com/content/iml/2011/03/16/sorting-a-matrix-by-row-or-column-statistics/

The post uses the SORTNDX function, which is explained further in this post: http://blogs.sas.com/content/iml/2011/03/14/sorting-rows-of-a-matrix/

In your example, IDX is not a valid index into X because IDX contains the value 10. The expression x[10] does not make sense because X has fewer than 10 elements. If you define r=rank(idx), then zz=x[r,] is defined.

Ranks and sorts can be confusing because sometimes you need to use the rank and sometimes you need to use the anti-rank.