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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 873 views
  • 4 likes
  • 3 in conversation