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

I have two matrices H and K

H = 1 2 3

K = 10 20

I woulde like to repeat K for each value of H - any suggestions? The expected result will look like

1     10

1     20

2     10

2     20

3     10

3     20

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

For a 2D grid, use this module, which is adapted from the article "How to create a grid of values"

start ExpandGrid(_x1, _x2);

   x1 = colvec(_x1);  Nx = nrow(x1);

   x2 = rowvec(_x2);  Ny = ncol(x2);

   X = repeat(x1, 1, Ny);

   Y = repeat(x2, Nx);

   return ( colvec(X) || colvec(Y) );

finish;

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ
KPatra
Calcite | Level 5

Thanks Rick, I have IML 12.1 and it does not have that function.

Rick_SAS
SAS Super FREQ

For a 2D grid, use this module, which is adapted from the article "How to create a grid of values"

start ExpandGrid(_x1, _x2);

   x1 = colvec(_x1);  Nx = nrow(x1);

   x2 = rowvec(_x2);  Ny = ncol(x2);

   X = repeat(x1, 1, Ny);

   Y = repeat(x2, Nx);

   return ( colvec(X) || colvec(Y) );

finish;

KPatra
Calcite | Level 5

Works like a charm, thanks Rick.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 1081 views
  • 0 likes
  • 2 in conversation