BookmarkSubscribeRSS Feed
azt5173
Obsidian | Level 7

I have two matrices [A ]   and {1,2,3} basically I need to combine the matrix that looks like {A1 A2 A3. 

                                 B                                                                                                             B1 B2 B3

                                 [C]                                                                                                           C1 C2 C3} 

The first matrix is for treatments(A,B,C) and the second matrix is for the age factor(1,2,3).

 

The resulting matrix will be used to check for imbalance between the treatments and age factor. 

 

I used the code below where basically tired to merge the two matrices:

 

proc iml;
M1={A,
B,
C};
M2={1 2 3};
nNames="B1":"B3";
cNames="A1":"A3";
create ndat from M1[colname=nNames];
append from M1;
create cdat from M2[colname=cNames];
append from M2;
quit;
data dat;
merge ndat cdat;
run;

 

This didn't really work as I still need to form a combination of two matrices. Any help will be appreciated. Thank you. 

4 REPLIES 4
Rick_SAS
SAS Super FREQ

Try this:

 

M1={A,B,C};
M2={1 2 3};
xy = expandgrid(M1, char(M2) ); /* 2 columns */
G = rowcatc(xy);   /* concatenate and get rid of blanks */
M = shape(G, nrow(M1)); /* shape into matrix */

nNames="B1":"B3";
cNames="A1":"A3";
print M[r=nNames c=cNames];
azt5173
Obsidian | Level 7

I have two matrices [A ]   and {1,2,3} basically I need to combine the matrix that looks like {A1 A2 A3. 

                                 B                                                                                                             B1 B2 B3

                                 [C]                                                                                                           C1 C2 C3} 

The first matrix is for treatments(A,B,C) and the second matrix is for the age factor(1,2,3).

 

The resulting matrix will be used to check for imbalance between the treatments and age factor. 

 

I used the code below where basically tired to merge the two matrices:

 

proc iml;
M1={A,
B,
C};
M2={1 2 3};
nNames="B1":"B3";
cNames="A1":"A3";
create ndat from M1[colname=nNames];
append from M1;
create cdat from M2[colname=cNames];
append from M2;
quit;
data dat;
merge ndat cdat;
run;

 

This didn't really work as I still need to form a combination of two matrices. Any help will be appreciated. Thank you. 

 

Cynthia_sas
SAS Super FREQ
Hi:
You'll probably get more answers if you post this in the forum for IML questions:
https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml

Cynthia
Ksharp
Super User
proc iml;
M1={A,
B,
C};
M2={1 2 3};
want=cats(repeat(m1,1,3),repeat(m2,3,1));
print want;
quit;

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
  • 876 views
  • 1 like
  • 4 in conversation