BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

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.

 

 

4 REPLIES 4
Ksharp
Super User
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;


LineMoon
Lapis Lazuli | Level 10

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.

 

Ksharp
Super User

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).

Rick_SAS
SAS Super FREQ

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 */

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1340 views
  • 4 likes
  • 3 in conversation