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

Hello-

I am attempting to divide the values in rows of matrix A by the values in rows of matrix B. the columns of both are the same variables, the rows are different though and the number of rows are different.

I have create a scaled down version below of what I am trying to do:

A{ 1 3, 4 5}

B{ 5 9, 6 2, 7 1}

C{ .2 .33, .166 1.5, .14 3,

.8 .55, .66 2.5, .57 5}

Simply using C=A/B doesn't work, But I am wondering what does? Or if I need to use something other than IML?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Let B1 = 1/B.  Then what you are describing is a "direct product" that involves A and B1.

SAS/IML has two direct products: the "full" direct product is P=A@B.  Your example is the first and last column of that direct product.

The second direct product is computed by using the HDIR function.  What you want is the transpose of HDIR(A`, B1`).

If this is something you intend to use often, you might want to use the following helper function:

start VDIR(A,B);
   return( T(hdir(A`,1/B`)) );
finish;

C = VDIR(A,B);

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

Let B1 = 1/B.  Then what you are describing is a "direct product" that involves A and B1.

SAS/IML has two direct products: the "full" direct product is P=A@B.  Your example is the first and last column of that direct product.

The second direct product is computed by using the HDIR function.  What you want is the transpose of HDIR(A`, B1`).

If this is something you intend to use often, you might want to use the following helper function:

start VDIR(A,B);
   return( T(hdir(A`,1/B`)) );
finish;

C = VDIR(A,B);

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 1308 views
  • 0 likes
  • 2 in conversation