turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2009 10:44 AM

Hi,

I am working with IML and I want to obtain a matrix of coefficient by assigning element by element something like this :

%macro cal(arguments);

.

.

.

%do ind=1 %to n;

%do sim=1 %to p;

.

.

.

proc iml;

.

.

.

RVCC[&ind,∼]=trace(s)/sqrt(trace(w**2)*trace(w2**2));

.

.

%end;

%end;

.

.

.

%mend

I have this error : "Matrix RVCC has not been set to a value"

Why do this occur?! Any one can help me?

Sincerly,

Nad

I am working with IML and I want to obtain a matrix of coefficient by assigning element by element something like this :

%macro cal(arguments);

.

.

.

%do ind=1 %to n;

%do sim=1 %to p;

.

.

.

proc iml;

.

.

.

RVCC[&ind,∼]=trace(s)/sqrt(trace(w**2)*trace(w2**2));

.

.

%end;

%end;

.

.

.

%mend

I have this error : "Matrix RVCC has not been set to a value"

Why do this occur?! Any one can help me?

Sincerly,

Nad

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2009 02:09 PM

You need to allocate the RVCC matrix before you assign to it. You can do that with a statement of the form:

RVCC = j(num_rows,num_cols);

You will need to figure out what num_rows and num_cols needs to be so that you don't exceed the maximum subscript value with RVCC[&ind,∼]=...

RVCC = j(num_rows,num_cols);

You will need to figure out what num_rows and num_cols needs to be so that you don't exceed the maximum subscript value with RVCC[&ind,∼]=...

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2009 03:54 PM

Allocation won't solve the problem because you have a call to PROC IML inside a macro loop. Every time PROC IML is called, the previous RVCC matrix is wiped out when PROC IML initializes.

The best way to arrange the code is to use an IML loop instead of a macro loop. If for some reason you can't do that (I suspect the "..." ellipses might involve other PROCs or DATA steps?) then you'll need to save the result of each iteration in a data set. You can say:

%macro cal();

%do ind=1 %to 5;

%do sim=1 %to 3;

proc iml;

ind = &ind;

sim = ∼ ;

RVCC = ind+sim;

if ind=1 & sim= 1 then

create RVCC var {ind sim RVCC};

else

edit RVCC var {ind sim RVCC};

append;

close RVCC;

quit;

%end;

%end;

%mend;

%cal();

proc print data=RVCC; run;

Or at the end you can reenter IML and use the SHAPE function to reshape your data:

proc iml;

use RVCC;

read all var {"RVCC"} into v;

close RVCC;

m = shape(v, 5, 3); /* reshape into 5x3 matrix */

print m;

The best way to arrange the code is to use an IML loop instead of a macro loop. If for some reason you can't do that (I suspect the "..." ellipses might involve other PROCs or DATA steps?) then you'll need to save the result of each iteration in a data set. You can say:

%macro cal();

%do ind=1 %to 5;

%do sim=1 %to 3;

proc iml;

ind = &ind;

sim = ∼ ;

RVCC = ind+sim;

if ind=1 & sim= 1 then

create RVCC var {ind sim RVCC};

else

edit RVCC var {ind sim RVCC};

append;

close RVCC;

quit;

%end;

%end;

%mend;

%cal();

proc print data=RVCC; run;

Or at the end you can reenter IML and use the SHAPE function to reshape your data:

proc iml;

use RVCC;

read all var {"RVCC"} into v;

close RVCC;

m = shape(v, 5, 3); /* reshape into 5x3 matrix */

print m;