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-30-2015 09:39 AM

I am looking for a way to delete all observations from a matrix based on conditions. For example, if I produced a simulation but subsequently wanted to delete all resulting rows that are less than 0 or greater than 1, how would I do that in IML?

This is easy to do in a DATA step, so I can do that, but I was curious regarding an IML approach. (It is probably discussed in Dr. Wicklin's text "Statistical Programming with SAS/IML Software," which I have and will examine, but I thought I would post the question here as it may be a more efficient way to find the answer.

Thanks

Brian

proc iml;

A = {0.50 0.50 0.50, -1 0.50 0.50, 2 0.50 0.50|;

B = matrix with rows that contain negative entries or entries greater than 1 removed

run;

The resulting matrix B should consist of {0.50 0.50 0.50} only.

Accepted Solutions

Solution

01-30-2015
02:16 PM

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

01-30-2015 02:16 PM

I suggest modifying the technique in the article Removing Observations with Missing Values - The DO Loop

C = (A<0 | A>1); /* matrix of zeros and ones */

count = c[,+]; /* add across rows */

keepIdx = loc(count=0); /* rows where all elements are in [0,1] */

if ncol(keepIdx)>0 then

B = A[keepIdx,];

else print "All rows of A are invalid";

All Replies

Solution

01-30-2015
02:16 PM

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

01-30-2015 02:16 PM

I suggest modifying the technique in the article Removing Observations with Missing Values - The DO Loop

C = (A<0 | A>1); /* matrix of zeros and ones */

count = c[,+]; /* add across rows */

keepIdx = loc(count=0); /* rows where all elements are in [0,1] */

if ncol(keepIdx)>0 then

B = A[keepIdx,];

else print "All rows of A are invalid";