I receive the error: "(execution) Invalid subscript or subscript out of range" when try to create a submatrix tmp which is based on matrix FD which contains all variables and observations from the dataset WFD (which contains 62 columns/variables and 2108 rows).
In tmp, I want to sum row 1 to 34, and row 35 to 69, and so on, until it reaches row 2074 to 2108 from the FD matrix, so that finally, the tmp matrix becomas a 62x62 matrix.
Do anyone see what I am doing wrong in my code?
Note: I have tried to find the mistake by looking in the log, i.e. by trying to find this reference point: operation: [ at line 2965 column 194, but I really don't understand where in the log I can find this lines and columns with really high numbers.
Help is very appreciated.
The code:
data tmpf ; set WFD;
run;
proc iml;
use tmpf(drop = year);
read all var _all_ into FD;
k = 0;
do i = 1 to 2108 by 34;
j = i+33;
k = k+1;
rows = i:j;
cols = k:k;
tmp = fd[rows,cols];
DMD = DMD // tmp ;
end;
The log:
NOTE: There were 14756 observations read from the data set WEBWORK.WFD.
I think the problem is the number of columns in FD. The log says it has 60 columns, however the loop:
do i = 1 to 2108 by 34;
will iterate 62 times. So the error is occuring on the 61st iteration when you try to access the 61st column.
Your code doesn't look right.
data tmpf ;
retain year 1;
array x{*} var1-var62;
do i=1 to 2108;
do j=1 to dim(x);
x{j}=ranuni(0);
end;
output;
end;
drop i j;
run;
proc iml;
i=0;
DMD=j(62,62,.);
use tmpf(drop = year);
do data;
read next 34 var _all_ into tmp;
i=i+1;
DMD[i,]=tmp[+,];
end;
close;
create want from dmd;
append from dmd;
close;
quit;
I think the problem is the number of columns in FD. The log says it has 60 columns, however the loop:
do i = 1 to 2108 by 34;
will iterate 62 times. So the error is occuring on the 61st iteration when you try to access the 61st column.
Thank you!
Indeed, I think that was the problem. I discovered that I made a mistake initially when I made the dataset (WFD) that I use to create the FD matrix, and therefore I had a smaller column range than planned. When I changed it to the correct one the code above worked.
Birgitte
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!