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,

I have been working on a code. This community helped me and taught me a lot. I have a question which may be very simple for you. In the below code when I use rowname statement I get this error 'Number of columns in X does not match with the number of variables in the data set'. Although rows and columns have the same candidates in the matrix, I don't understand why I get this error. 

 

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;
read all var _ALL_;
close tr;

Cand=unique(Cand_1//Cand_2);
call sort(Cand);

X=j(ncol(Cand), ncol(Cand), .);

do i=1 to nrow(RT_PROB);
X[loc(Cand=Cand_1[i]),loc(Cand=Cand_2[i])]=RT_PROB[i];
end;

print X[colName=((Cand)) rowName=((Cand))];
create matrix from X [colname=Cand rowname=Cand];
append from X;
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Because you are writing an extra column (the ROWNAME= variable), you need to include that information on the APPEND statement:

 

create matrix from X [colname=Cand rowname=Cand];
append from X[rowname=Cand];
close;

 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Hi @dustychair. Glad to hear that the community has taught you some 🙂 

 

My guess is that you do not want to create another matrix from X, rather a data set, correct? If so then change this

 

create matrix from X [colname=Cand rowname=Cand];
append from X;

to this

 

create data MyData from X[colname=Cand];
   append from X;
close MyData;
dustychair
Pyrite | Level 9

Hi Draycut,

Actually my main purpose is to use X matrix (or should I say data set?) in cluster analysis. In cluster analysis I need to define variables.Candidates will be clustered based on RT_PROB. So, I have to define both variables. Maybe there is an easy way to do that but I tried proc transpose  to get cand variable in the rows. Here is my whole code for my purpose.

 

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;
read all var _ALL_;
close tr;

Cand=unique(Cand_1//Cand_2);
call sort(Cand);

X=j(ncol(Cand), ncol(Cand), .);

do i=1 to nrow(RT_PROB);
X[loc(Cand=Cand_1[i]),loc(Cand=Cand_2[i])]=RT_PROB[i];
end;

print X[colName=((Cand)) rowName=((Cand))];
create matrix from X [colname=Cand rowname=Cand];
append from X;
quit;


data matrix;
set matrix;
array change _numeric_;
do over change;
if change=. then change=0;
end;
run ;

 

proc transpose data=matrix
out=matrix1;
run;


ods graphics on;

proc cluster data=matrix1 method=ward ccc pseudo out=tree;
var RT_PROB;
id cand;

run;

ods graphics off;

proc tree data=matrix1 out=New nclusters=5 noprint ;


run;

Rick_SAS
SAS Super FREQ

Because you are writing an extra column (the ROWNAME= variable), you need to include that information on the APPEND statement:

 

create matrix from X [colname=Cand rowname=Cand];
append from X[rowname=Cand];
close;