Statistical programming, matrix languages, and more

Repeat by variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Repeat by variable

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


Accepted Solutions
Solution
‎03-17-2015 10:51 AM
SAS Super FREQ
Posts: 3,406

Re: Repeat by variable

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


All Replies
SAS Super FREQ
Posts: 3,406

Re: Repeat by variable

Occasional Contributor
Posts: 8

Re: Repeat by variable

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

Solution
‎03-17-2015 10:51 AM
SAS Super FREQ
Posts: 3,406

Re: Repeat by variable

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;

Occasional Contributor
Posts: 8

Re: Repeat by variable

Works like a charm, thanks Rick.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 351 views
  • 0 likes
  • 2 in conversation