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

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Matrix Multiplication using Hash Object

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-10-2016 02:08 PM

Hi All,

Looking for optimal ways to multiply two matrices with out using IML. Is it possible to use Hash object to accomplish the task?

A = 1 3 B = 1 1 A*B = 7 7

2 4 2 2 10 10

Thanks

Accepted Solutions

Solution

03-17-2016
08:58 AM

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

03-10-2016 02:55 PM

Hash objects would be a poor choice. Two-dimensional arrays could work, however.

Within a SAS data set, there is no such construct as a matrix. There are tons of variables. So it would be up to you to track what dimensions to use for your matrices and what variables go where. You could certainly code something along these lines:

array a {2,3} a1-a6;

array b {3,2} b1-b6;

array dotprod {2,2} dotprod1-dotprod4;

do i=1 to 2;

do j=1 to 3;

** construct 2 dotprod elements here;

end;

do j=4 to 6;

** construct 2 more dotprod elements here;

end;

end;

This would be "optimal" in the sense that it runs quickly. But you still have to do a lot of the planning and thinking.

All Replies

Solution

03-17-2016
08:58 AM

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

03-10-2016 02:55 PM

Hash objects would be a poor choice. Two-dimensional arrays could work, however.

Within a SAS data set, there is no such construct as a matrix. There are tons of variables. So it would be up to you to track what dimensions to use for your matrices and what variables go where. You could certainly code something along these lines:

array a {2,3} a1-a6;

array b {3,2} b1-b6;

array dotprod {2,2} dotprod1-dotprod4;

do i=1 to 2;

do j=1 to 3;

** construct 2 dotprod elements here;

end;

do j=4 to 6;

** construct 2 more dotprod elements here;

end;

end;

This would be "optimal" in the sense that it runs quickly. But you still have to do a lot of the planning and thinking.