BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sykim
Calcite | Level 5
I am trying to do matrix operations on SAS using a dataset I call 'ao' which has 7 variables and which I have attached. As an experiment, I am doing a scalar operation on the data I read in as a matrix, and I want to output it back out as a sas dataset using the following code:


proc iml;
use aoy;
read all var _ALL_ into Gamma[colname=varNames];
y=2*Gamma;
close ao;
create test from y[colname={"ind2" "MRP" "SMB" "HML" "RMW" "CMA" "RF"}];;
append from test;
close test;
quit;

For some reason SAS gives me the error message:"Number of columns in test does not match with the number of variables in the data set". I don't see how this is posssible because the dataset has exactly 7 variables. Please let me know if there is anything wrong with the code. I have attached the dataset for convenience.
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Your code is not right.


proc import datafile='/folders/myfolders/aoy.xlsx' out=aoy dbms=xlsx replace;run;
proc iml;
use aoy;
read all var _ALL_ into Gamma[c=vnames];
close;
y=2#Gamma;
create test from y[colname=vnames];
append from y;
close test;
quit;

View solution in original post

2 REPLIES 2
Ksharp
Super User
Your code is not right.


proc import datafile='/folders/myfolders/aoy.xlsx' out=aoy dbms=xlsx replace;run;
proc iml;
use aoy;
read all var _ALL_ into Gamma[c=vnames];
close;
y=2#Gamma;
create test from y[colname=vnames];
append from y;
close test;
quit;

sykim
Calcite | Level 5

Thanks, this works now!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1893 views
  • 0 likes
  • 2 in conversation