I have a matrix G that contains 2 missing values:
G | ||||
0.0909091 | 0.2 | 1 | 0.6666667 | 0.2857143 |
0.1428571 | 0.2857143 | 0.2 | . | 0.25 |
-2 | 0.1538462 | -2 | -0.181818 | 0.6666667 |
-0.666667 | -1 | 0.1538462 | -1 | 0.5 |
0.2222222 | 0.25 | 2 | -1 | 0.5 |
0.2222222 | 2 | -0.285714 | 0.4 | -2 |
1 | -0.333333 | 0.3333333 | 0.4 | 2 |
0.5 | 0.4 | . | -1 | 1 |
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?
use the LOC function to find the entries that are missing. Then use assignment to replace those values:
idx = loc( G = . );
G[ idx ] = 0;
use the LOC function to find the entries that are missing. Then use assignment to replace those values:
idx = loc( G = . );
G[ idx ] = 0;
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
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;
SYSVLONG = 9.03.01M1P
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;
That worked. Thank you again.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.