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);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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