Hi all,
I am receiving the following error: "ERROR: (execution) Matrix has not been set to a value." when using Proc IML. Any assistance that can be provided is much appreciated.
Here is my code:
proc iml;
use work.prof;
read all var {jun04 jul04 aug04 sep04 oct04 nov04 dec04 jan05 feb05 mar05 apr05 may05 jun05 jul05 aug05 sep05 oct05 nov05 dec05 jan06 feb06 mar06 apr06 may06 jun06 jul06 aug06 sep06 oct06 nov06 dec06 jan07 feb07 mar07 apr07 may07 jun07 jul07 aug07 sep07 oct07 nov07 dec07 jan08 feb08 mar08 apr08 may08 jun08 jul08 aug08 sep08 oct08 nov08 dec08 jan09 feb09 mar09 apr09 may09 jun09 jul09 aug09 sep09 oct09 nov09 dec09 jan10 feb10 mar10 apr10 may10 jun10 jul10 aug10 sep10 oct10 nov10 dec10 jan11 feb11 mar11 apr11 may11 jun11 jul11 aug11 sep11 oct11 nov11 dec11 jan12 feb12 mar12 apr12 may12 jun12 jul12 aug12 sep12 oct12 nov12 dec12 jan13 feb13 mar13 apr13 may13 jun13 jul13 aug13 sep13 oct13 nov13 dec13 jan14 feb14 mar14 apr14 may14 jun14 jul14 aug14 sep14 oct14 nov14 dec14 jan15 feb15 mar15 apr15 may15} into matrix;
n_months=ncol(matrix);
n_farms=nrow(matrix);
Profits = j(n_farms,n_months,0);
exit = j(n_farms,n_months,0);
real=(profits=0);
do i=1 to n_farms;
do j=4 to n_months;
profits[i,j]=matrix[i,j-1]+matrix[i,j-2]+matrix[i,j-3];
if profit[i,j]<0 then exit[i,j]=1;
end;
end;
accuracy=(real=exit);
percent=mean(accuracy);
print percent;
quit;
Here is the log:
Hi Rick,
Thanks for catching that. There is still another error, however. I think the do-loop is not executing for some reason. When I print the 'profits' matrix it displays a matrix of all zeros. If you can assist me with this error, I would greatly appreciate it.
Thanks,
Dylan
The error message says that a matrix is not define. If you look closer, you can find the message
Hi Rick,
Thanks for catching that. There is still another error, however. I think the do-loop is not executing for some reason. When I print the 'profits' matrix it displays a matrix of all zeros. If you can assist me with this error, I would greatly appreciate it.
Thanks,
Dylan
I don't see anything obviously wrong, so perhaps it is your data. If I replace your USE and READ statements by
use sashelp.cars;
read all var _NUM_ into matrix;
then the 'profits' matrix contains the values that I would expect.
You'd better give us some data to test it. Why not use Vector operation ? do i=1 to n_farms; do j=4 to n_months; profits[i,j]=matrix[i,j-1]+matrix[i,j-2]+matrix[i,j-3]; if profit[i,j]<0 then exit[i,j]=1; end; end; ->> do j=4 to n_months; profits[ ,j]=matrix[ ,j-1]+matrix[ ,j-2]+matrix[ ,j-3]; end; exit=(profit<0);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.