Statistical programming, matrix languages, and more

SAS/IML: ERROR: (execution) Matrix has not been set to a value.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

SAS/IML: ERROR: (execution) Matrix has not been set to a value.

[ Edited ]

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:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 proc iml;
NOTE: IML Ready
57 use work.prof;
58 read all var {jun04jul04
58 ! aug04sep04oct04nov04dec04jan05feb05mar05apr05may05jun05jul05aug05sep05oct05nov05dec05jan06feb06mar06a
58 ! pr06may06jun06jul06aug06sep06oct06nov06dec06jan07feb07mar07apr07may07jun07jul07aug07sep07oct07nov07de
58 ! c07jan08feb08mar08apr08may08jun08jul08aug08sep08oct08nov08dec08jan09feb09mar09apr09may09jun09jul09aug
58 ! 09sep09oct09nov09dec09jan10feb10mar10apr10may10jun10jul10aug10sep10oct10nov10dec10jan11feb11mar11apr1
58 ! 1may11jun11jul11aug11sep11oct11nov11dec11jan12feb12mar12apr12may12jun12jul12aug12sep12oct12nov12dec12
58 ! jan13feb13mar13apr13may13jun13jul13aug13sep13oct13nov13dec13jan14feb14mar14apr14may14jun14jul14aug14
58 ! sep14oct14nov14dec14jan15feb15mar15apr15may15} into matrix;
59 n_months=ncol(matrix);
60 n_farms=nrow(matrix);
61 Profits = j(n_farms,n_months,0);
62 exit = j(n_farms,n_months,0);
63 real=(profits=0);
64 do i=1 to n_farms;
64 !
65
65 ! do j=4 to n_months;
66
66 ! profits[i,j]=matrix[i,j-1]+matrix[i,j-2]+matrix[i,j-3];
67
67 ! if profit[i,j]<0 then exit[i,j]=1;
68
68 ! end;
69 end;
ERROR: (execution) Matrix has not been set to a value.
 
operation : [ at line 67 column 11
operands : profit, i, j
 
profit 0 row 0 col (type ?, size 0)
 
 
i 1 row 1 col (numeric)
 
1
 
j 1 row 1 col (numeric)
 
4
 
statement : IF at line 67 column 2
70 accuracy=(real=exit);
71 percent=mean(accuracy);
72 print percent;
73 quit;
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.22 seconds
cpu time 0.23 seconds

 

 


Accepted Solutions
Solution
‎04-10-2016 02:21 PM
Occasional Contributor
Posts: 13

Re: SAS/IML: ERROR: (execution) Matrix has not been set to a value.

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

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,615

Re: SAS/IML: ERROR: (execution) Matrix has not been set to a value.

The error message says that a matrix is not define. If you look closer, you can find the message

>   profit 0 row 0 col (type ?, size 0)
 
This tells you that 'profit' is not defined.  If you review the program, you will see that the similar-sounding variable 'profits' is defined, so I suspect you mistyped 'profits' as 'profit'.
 
For information about how to find and fix errors in SAS/IML, see
and
 
Solution
‎04-10-2016 02:21 PM
Occasional Contributor
Posts: 13

Re: SAS/IML: ERROR: (execution) Matrix has not been set to a value.

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

SAS Super FREQ
Posts: 3,615

Re: SAS/IML: ERROR: (execution) Matrix has not been set to a value.

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.

 

Super User
Posts: 9,854

Re: SAS/IML: ERROR: (execution) Matrix has not been set to a value.

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


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 859 views
  • 2 likes
  • 3 in conversation