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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4004 views
  • 1 like
  • 2 in conversation