Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-24-2018 03:07 AM
(2179 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

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 16. Read more here about **why** you should contribute and **what is in it** for you!

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.