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.
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;
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.
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).
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 */
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.