Hi everyone,
I have a matrix created based on raw data. I want to use this matrix as input for cluster analysis. Can anyone help me to define that matrix as input? Here is the code I use. I tried that code but it did not work. I don't know what I'm missing. I also attached raw data I used.
Thanks
data tr;
infile 'C:\coll_gen\N100\GROUP10\COMP40\PHI25\gbt\RESULTS-SIG1.OUT';
input CAND_1$ CAND_2$ ID_1 ID_2 THETA_1 THETA_2 MATCHES RT_PROB FLAG ;
run;
proc iml;
use tr nobs nobs;
read all var{CAND_1 CAND_2 RT_PROB};
close;
levels=unique(CAND_1||CAND_2);
matrix1=j(ncol(levels),ncol(levels),.);
mattrib matrix1 r=((levels)) c=((levels)) label='' ;
row=(CAND_1);
col=(CAND_2);
do i=1 to nobs;
r=row[i];c=col[i];p=RT_PROB[i];
matrix1[r,c]=p;
end;
print matrix1;
quit;
ods graphics on;
proc cluster data=matrix1 method=ward ccc pseudo out=tree;
var RT_PROB;
id CAND_1;
run;
ods graphics off;
proc tree data=matrix1 out=New nclusters=5 noprint ;
height _rsq_;
copy RT_PROB ;
run;
You can export row and column names at the same time as the matrix. For example:
create matrix1 from matrix1 [rowname=levels colname=levels];
append from matrix1 [rowname=levels ];
All the matrices in IML are destroyed when you exit the procedure with 'quit'. In order to do what you want, you will need to add the IML statements:
create matrix1 from matrix1;
append from matrix1;
to export the contents of matrix1 to a SAS data set. There are other problems as matrix1 will be very sparse, mostly with missing values, and you will not be able to run a cluster analysis on it.
Hi lanWakeling,
Thanks for your response,
I added the statements you mentioned. Now I have the matrix but it does not have the candidates id numbers in rows and columns. I attached the output.
Thanks
You can export row and column names at the same time as the matrix. For example:
create matrix1 from matrix1 [rowname=levels colname=levels];
append from matrix1 [rowname=levels ];
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.