turn on suggestions

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

Showing results for

Find a Community

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-20-2015 10:25 AM

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?

Accepted Solutions

Solution

10-20-2015
10:55 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xtc283x

10-20-2015 10:46 AM

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

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

All Replies

Solution

10-20-2015
10:55 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xtc283x

10-20-2015 10:46 AM

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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

10-21-2015 08:23 AM

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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xtc283x

10-21-2015 08:29 AM

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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

10-21-2015 08:37 AM

SYSVLONG = 9.03.01M1P

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xtc283x

10-21-2015 08:57 AM

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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

10-21-2015 09:36 AM

That worked. Thank you again.