## IML proc and the checking of the matrix element as a probability

Super Contributor
Posts: 376

# IML proc and the checking of the matrix element as a probability

[ Edited ]

Hello Expert,

When we use IML PROC to calcule a matrix element (Mij) as a probabilty, So Mij will respect this condition.

0<=Mij<=1.

Please, Is there any method - without coding-  to transfore Mij<0 or Mij>1 as error and stop the treatement ?

Thank you.

Super User
Posts: 10,700

## Re: IML proc and the checking of the matrix element as a probability

What do you mean by "without coding" ?

proc iml;
x={1.1 0.9,0.7 1.2};
if any(x>1 | x<0) then abort;
else print 'Good';
quit;

Super Contributor
Posts: 376

## Re: IML proc and the checking of the matrix element as a probability

Thank you very much

What's I mean by "without coding" ?

Your answer is correct. But in some cases, we can have so many programs without your check

if any(x>1 | x<0) then abort;

In this case, we must have to code "if any(x>1 | x<0)  then abort" in every program.

So, I am looking for some global option- if exist- to do the check without coding the condition in every Matrix.

Thank you.

Super User
Posts: 10,700

## Re: IML proc and the checking of the matrix element as a probability

No. You can't . SAS unlike Jave or other Object-Orientation Language.

SAS can't create a brand-new CLASS ,can't overwrite/overload a CLASS. therefore you can't create a special Object(Matrix).

SAS Super FREQ
Posts: 4,181

## Re: IML proc and the checking of the matrix element as a probability

This is a classic use case for a macro, which performs text substitution. Define a macro such as

%macro CheckProb(m);
if any(&m>1 | &m<0) then abort "Matrix &m out of range";
else;
%mend;

Then any time you want to check whether a matrix has elements outside of [0,1] just insert the macro call, like this:

proc iml;
x={1.1 0.9,0.7 1.2};
%CheckProb(x)
/* continue the program */
Discussion stats
• 4 replies
• 294 views
• 4 likes
• 3 in conversation