BookmarkSubscribeRSS Feed
nadra
Calcite | Level 5
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
2 REPLIES 2
Hutch_sas
SAS Employee
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,∼]=...
Rick_SAS
SAS Super FREQ
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 930 views
  • 0 likes
  • 3 in conversation