BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xtc283x
Quartz | Level 8

I have a matrix that contains 2 missing values:

 

G
0.09090910.210.66666670.2857143
0.14285710.28571430.2.0.25
-20.1538462-2-0.1818180.6666667
-0.666667-10.1538462-10.5
0.22222220.252-10.5
0.22222222-0.2857140.4-2
1-0.3333330.33333330.42
0.50.4.-11

 

The CALL CHANGE function only works on text fields. And I don't understand the explanations for the REPLACE function.

 

What is the logic in SAS/IML to replace those two missing values with 0?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

use the LOC function to find the entries that are missing. Then use assignment to replace those values:

 

idx = loc( G = . );
G[ idx ] = 0;

View solution in original post

6 REPLIES 6
Rick_SAS
SAS Super FREQ

use the LOC function to find the entries that are missing. Then use assignment to replace those values:

 

idx = loc( G = . );
G[ idx ] = 0;
xtc283x
Quartz | Level 8

Thank you. Using LOC() and idx() worked. Using the same matrix G, I'm getting a new error in applying it to the norm() module. Here's the line of code:

 

    GFrob = norm(G, "Frobenius");

 

And the error is "ERROR: Invocation of unresolved module NORM."

 

Based on a post in The Do Loop, this code should work!  

 

http://blogs.sas.com/content/iml/2014/04/07/vector-and-matrix-norms-in-sas.html

 

Rick_SAS
SAS Super FREQ

The first sentence of the blog says that you need SAS/IML 12.1, which was shipped in August 2012 as part of SAS 9.3m2.

 

What do you get when you run the following statement?

%put SYSVLONG = &SYSVLONG;

xtc283x
Quartz | Level 8

SYSVLONG = 9.03.01M1P

Rick_SAS
SAS Super FREQ

That answers the question: You are running SAS 9.3.

 

Now what to do about it? There have been five releases of SAS since SAS 9.3, so you might consider upgrading.

 

In the meantime, most norms are trivial to program. Here's a SAS/IML function that computes the Frobenius, L1, L2, and "L infinity" norms for matrices:

start matnorm(x, method);
   s = substr(upcase(method), 1, 4);
   isValid = (s="FROB" | s="L1" | s="LINF" | s="L2");
   if ^isValid then return(.);
   
   if (s="FROB") then do;
      return( sqrt(x[##]) );
   end;
   else if (s="L1") then do;
      return( max(x[+,]) );
   end;
   else if (s="LINF") then do;
      return( max(x[,+]) );
   end;
   else if (s="L2") then do;
      v = eigval(x`*x);
      return( sqrt(v[1]) );
   end;
finish;


/* Test the module on the doc example */

x={1 2, 3 4};
mn1 = matnorm(x, "L1");
mnF = matnorm(x, "Frobenius");
mnInf = matnorm(x, "LInf");
print mn1 mnF mnInf;
xtc283x
Quartz | Level 8

That worked. Thank you again.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 2990 views
  • 2 likes
  • 2 in conversation