BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bhfield
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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";

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

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";