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

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

12-06-2015 05:59 AM

In IML, is there any way to find every occurrence of a certain number in a matrix and replace it with another number, and what is the syntax for this?

Accepted Solutions

Solution

12-07-2015
08:35 PM

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

Posted in reply to dvtarasov

12-06-2015 06:52 AM

The LOC function will find the location of the elements that you are looking for. Then you can use regular assignment to replace the numbers. For example, to replace all values -99 with a missing value, do the following:

```
proc iml;
x = {1 -99 3 4,
5 6 -99 8};
idx = loc(x = -99); /* find location of elements */
x[idx] = .; /* replace those elements */
```

All Replies

Solution

12-07-2015
08:35 PM

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

Posted in reply to dvtarasov

12-06-2015 06:52 AM

The LOC function will find the location of the elements that you are looking for. Then you can use regular assignment to replace the numbers. For example, to replace all values -99 with a missing value, do the following:

```
proc iml;
x = {1 -99 3 4,
5 6 -99 8};
idx = loc(x = -99); /* find location of elements */
x[idx] = .; /* replace those elements */
```