BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sai_ch
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

 

View solution in original post

1 REPLY 1
Astounding
PROC Star

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 801 views
  • 0 likes
  • 2 in conversation