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-19-2014 02:15 AM

I want to replace missing value in a matrix A with zero and first need to find their locations in the matrix. Since function loc() treats the missing values as zero, how can I use the function to find their locations in A?

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

Posted in reply to ShufeGuoding

12-19-2014 06:19 AM

proc iml;

A = {. 2 3, 4 . 6};

idx = loc(A=.);

A[idx] = 0;

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

Posted in reply to Rick_SAS

12-20-2014 07:28 PM

Because missing values are treated as zero, Your code seems not work properly. The problem is the same as that I met.

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

Posted in reply to ShufeGuoding

12-20-2014 07:37 PM

Works fine for me, idx identifies the missing as 1, 5. Next line replaces them to be 0's.

proc iml;

A = {. 2 3, 4 . 6};

idx = loc(A=.);

print idx;

A[idx] = 0;

print a;

OUTPUT:

The SAS System

1 | 5 |

0 | 2 | 3 |

4 | 0 | 6 |

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

Posted in reply to Reeza

12-21-2014 03:32 AM

I get it. Thanks a lot!

Steve

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

Posted in reply to ShufeGuoding

12-21-2014 01:12 PM

As far as I know, missing values are not "treated as zero" anywhere in IML. You might be thinking of the behavior of an IF/THEN-ELSE statement, where a missing value in the IF conditional results in the condition evaluating to FALSE.

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

Posted in reply to Rick_SAS

12-21-2014 07:23 PM

I was misleaded by the statements for Loc function in Usg/IML12.1 that read:

The loc funciton finds nonzero elements of a matix. .... . Missing values treated as zeros.:smileyconfused:

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

Posted in reply to ShufeGuoding

12-22-2014 07:40 AM

I see. I interpret that phrase to mean that

y = loc(x);

will produce a matrix y such that y[i,j]=0 whenever x[i,j] is zero or missing, but I see how that phrase might be confusing. To make sure you always get the correct answer, I recommend using a logical expression as the argument to the LOC function. For example

y = loc(x^=0);

or

y = loc(x>0);

etc