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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

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

 

View solution in original post

3 REPLIES 3
IanWakeling
Barite | Level 11

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.

 

dustychair
Pyrite | Level 9

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

IanWakeling
Barite | Level 11

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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 1401 views
  • 3 likes
  • 2 in conversation