Hi,
I have a matrix of ownership data with a max of two decimals. The matrix consists of 1200 columns and 800 rows. My code reads one row at a time and determines whether ownership has gone up, down or stayed the same by moving across the columns.
This is the code:
Proc iml;
use work.data;
Read all var_num_into M;
C=1200;
R=800;
buysell=J(R,C-1,0);
Do j=1 to R;
Do i=1 to N-1;
If M[j,i+1]>M[j,i] then buysell[j,i]=1;
If M[j,i+1]<M[j,i] then buysell[j,i]=-1;
If M[j,i+1]=M[j,i] then buysell[j,i]=0;
end;
end;
create invdata from buysell;
append from buysell;
quit;
Can't seem to find a problem with my code. It does what I want most of the time, but sometimes it makes a mistake. For example at one point where M[78,i+1] and M[78,i+1] both are equal to 0.21 it assigns the value 1 (meaning ownership went up) instead of 0 (meaning ownership is unchanged). Do not have more than two decimals in my imported excel sheet, so can't see how it is a rounding problem.
Hope i explained it all right and that someone can help,
Jacob
I have a matrix of ownership data with a max of two decimals. The matrix consists of 1200 columns and 800 rows. My code reads one row at a time and determines whether ownership has gone up, down or stayed the same by moving across the columns.
This is the code:
Proc iml;
use work.data;
Read all var_num_into M;
C=1200;
R=800;
buysell=J(R,C-1,0);
Do j=1 to R;
Do i=1 to N-1;
If M[j,i+1]>M[j,i] then buysell[j,i]=1;
If M[j,i+1]<M[j,i] then buysell[j,i]=-1;
If M[j,i+1]=M[j,i] then buysell[j,i]=0;
end;
end;
create invdata from buysell;
append from buysell;
quit;
Can't seem to find a problem with my code. It does what I want most of the time, but sometimes it makes a mistake. For example at one point where M[78,i+1] and M[78,i+1] both are equal to 0.21 it assigns the value 1 (meaning ownership went up) instead of 0 (meaning ownership is unchanged). Do not have more than two decimals in my imported excel sheet, so can't see how it is a rounding problem.
Hope i explained it all right and that someone can help,
Jacob