Statistical programming, matrix languages, and more

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

Reply
Contributor
Posts: 38

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

Hello,

I am new in using SAS. Running somebody else code and I see this error in the middle of the code.

Any Idea,

Thank you

SAS Super FREQ
Posts: 3,234

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

This occurs when you try to assign or print a matrix that has not been assigned.

For example:

proc iml;

y = x; /* x has not been assigned */

Contributor
Posts: 38

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

Thank you.

Contributor
Posts: 38

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

This is the macro and all values to be sent to macro is provided prior in the code:

%macro addmargins(fob,truck,rail,water,air,pipe,whole,ret,fsv,filter=(1:num_sectors));

        selector = J(1,num_sectors,0);

        selector[&filter] = 1;

        Yplus = diag(selector) * &fob;

        /* transportation margins */

        Yplus[truck_row,] = Yplus[truck_row,] + selector * &truck;

        Yplus[air_row,] = Yplus[air_row,] + selector * &air;

        Yplus[water_row,] = Yplus[water_row,] + selector * &water;

        Yplus[rail_row,] = Yplus[rail_row,] + selector * &rail;

        Yplus[pipe_row,] = Yplus[pipe_row,] + selector * &pipe;

        Yplus[fsv_row,] = Yplus[fsv_row,] + selector * &fsv;

        /* wholesale & retail utility and non-utility expenditure */

        Yplus[tgas_row,] = Yplus[tgas_row,] +

            selector * (diag(fuel_w) * &whole + diag(fuel_r) * &ret);

        Yplus[telec_row,] = Yplus[telec_row,] +

            selector * (diag(elec_w) * &whole + diag(elec_r) * &ret);

        Yplus[whole_row,] = Yplus[whole_row,] +

            selector * ((I(num_sectors) - diag(elec_w + fuel_w)) * &whole);

        Yplus[retail_row,] = Yplus[retail_row,] +

            selector * ((I(num_sectors) - diag(elec_r + fuel_r)) * &ret);

    %mend;

and here is when error happens:

3526  /*Read in macro to compute and add margin costs to PCE columns*/

3527      %include 'C:\Users\hze1\Desktop\SAS\FMB addmargins macro.sas';

3549      %addmargins(fob=Y_nipa, truck=N_truck, rail=N_rail,

3550                  water=N_water, air=N_air, pipe=N_pipe,

3551                  whole=N_whole, ret=N_ret, fsv=N_fsv);

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

operation : [ at line 3549 column 5

operands  : Yplus, fsv_row,

Yplus    392 rows    228 cols    (numeric)

fsv_row      0 row       0 col     (numeric)

statement : ASSIGN at line 3549 column 5

ERROR: (execution) Matrices do not conform to the operation.

SAS Super FREQ
Posts: 3,234

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

The tenth line of the macro is

   Yplus[fsv_row,] = Yplus[fsv_row,] + selector * &fsv;

On that line, the variable fsv_row has not been set to a value.

You might want to read this article on "How to interpret SAS/IML error messages."

Contributor
Posts: 38

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

On the tenth line exactly same thing happening that is happening on the above lines in macro:-(

SAS Super FREQ
Posts: 3,234

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

I don't understand your response. I am telling you where the error occurs. You haven't provided enough information to know WHY the error is occuring.

You might want to send more of the SAS Log.  If necessary, look up the the SAS system options MLOGIC, MPRINT, and SYMBOLGEN. They are sometimes helpful in debugging macros.

Of course, asking the person who wrote the code might help. It's possible that you are using his macro incorrectly or forgot to set some option.

Occasional Contributor
Posts: 5

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

Hi everybody,

 

I am new to the SAS community.

I am a SAS user (Enterprise Guide 5.1) and I am encountering a problem with SAS IML.

 

Error message: 

  " ERROR: (execution) Matrix has not been set to a value."

 

Extract of code:

proc iml ;

use KERNEL.RFSS&simu.;
read all var _ALL_ into rfss;
close;
/*start transpose(rfss);
t_rfss=T(rfss);
return(t_rfss);
finish;*/

use KERNEL.apf2;
read all var _ALL_ into apf;
close;

use KERNEL.lapf2;
read all var _ALL_ into lapf;
close;

use KERNEL.lpf2;
read all var _ALL_ into lpf;
close;


Arr=repeat(0,NROW(apf),NCOL(apf));

 

n_mon=NROW(apf);
n_rf=NCOL(apf);
%put n_mon;
%put n_rf;

 

%do r=1 %to &Nrf.;
Arr[1:NROW(apf),r] = rfss[r]**apf[1:NROW(apf),r];
%end;

 

create results&simu.
from Arr;
append from Arr;
close;
quit;

 

The code executes well when I deactivate the part in bold.

I read a lot of debugging hints on this website. But I still do not have a solution to the problem.

At first, I thought it was a dimension problem.  Then I put all the matices apf and Arr to the same dimensions. 

Do you think there is a problem with the dimension of vector rfss[r] ? The idea here is to raise each component of rfss[r] to the power at each column of matrix apf.

Thanks so much for your help.

 

Oh yeah: apf has 20,000 rows and 96 columns. rfss[r] has 1 row and 96 columns and Arr is supposed to be a  20,000 rows X 96 columns matrix.

 

Raphael

SAS Super FREQ
Posts: 3,234

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

Hi @NewbieRaph. Welcome to SAS and IML.  I'll answer your question, but in the future please open a new discussion rather than appending to a thread that has been closed for three years.

 

First, there is no need for a macro loop. The SAS/IML loop has a DO loop that will enable you to perform this calulation without using macro. (The macro loop is also inefficient, since it generates 96 separate statements that have to be parsed and executed.)

Here's how to use a DO loop:

proc iml;
apf = {1 2 3,
       4 5 6};
rfss = {2 3 4};
Arr=repeat(0,NROW(apf),NCOL(apf)); do r=1 to ncol(apf); Arr[1:NROW(apf),r] = rfss[r]**apf[1:NROW(apf),r]; end; print Arr;

Second, for this computation, you actually don't need any loop. SAS/IML is a matrix language, which means it can perform matrix and vector computation.  The elementwise power operator is ##, which you can use to raise each element of a vector to a power. (The '**' operator is for repeated matrix multiplication.) Thus your program reduces to the one-liner:

 

Arr = rfss##apf;
print Arr;

For more details, see the article "Shorthand notation for row and column operations."

 

Occasional Contributor
Posts: 5

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

Whoa! Thanks very much @Rick_SAS!! Really.

I did not know about the tip:

"Arr = rfss##apf;"

That's helpful.

And sorry, if I opened this old discussion. I actually did not know how to open a new one. But now I do.

 

Raphael

Post a Question
Discussion Stats
  • 9 replies
  • 4730 views
  • 0 likes
  • 3 in conversation