Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-20-2015 10:25 AM
(2777 views)

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?

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

SYSVLONG = 9.03.01M1P

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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.