BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Obsidian | Level 7

The matrix in the modules

hey guys,

I put a matrix as an arguement in the start finish module, but it seems to exist some problem, that some loops work but some not. Can I set a matrix as an arguement in the start-finish module?

``````%macro calculate();

%do i=1 %to 2320;

%let e=%sysfunc(cat(&i));
%let first="spl1.split";
%let name="";

data _null_;
b=&e;
a=&first;
x=strip(a)||strip(b);
call symput("name",x);
run;
%put &name;

proc iml;
load D;
load LL;

start LLH(st,fi,S);
b_1=(S[st:(fi-1),4]`)*S[(st+1):fi,4]/((S[st:(fi-1),4]`)*S[st:(fi-1),4]);
b_2s=S[(st+1):fi,4]-b_1*S[st:(fi-1),4];
b_2=b_2s[:];
sigma_s1=S[(st+1):fi,4]-b_1*S[st:(fi-1),4]-b_2;
sigma_s2=sigma_s1##J((fi-st),1,2);
sigma=(fi-st-1)/(fi-st-2)*sigma_s2[:];
LLF=(-0.5*(fi-st-1))*log(2*arcos(-1)*(sigma))-1/(2*sigma)*((S[st:(fi-1),4]`)*S[st:(fi-1),4]);
return(LLF);
finish LLH;

use &name;
%do t=1 %to 120;
g=D[&t,1];
read all where(COL2=g) into SS;
LL[&i,&t]=LLH(1,15,SS);
%end;
store LL;
quit;
%end;
%mend;

%calculate();``````

1 ACCEPTED SOLUTION

Accepted Solutions
Barite | Level 11

Re: The matrix in the modules

When there is no data to read, I think you will get a warning message in the log file and the matrix SS will be undefined.  This will most likely create problems later on, so you need to test for the empty matrix.  For example:

``````if nrow(SS) = 0
then print 'No data found!';
else do;
< do stuff with SS>
end;``````
3 REPLIES 3
SAS Super FREQ

Re: The matrix in the modules

Yes, you can set a matrix as an argument in a module.

I don't think there is a reason to use this macro loop.  Just use the standard SAS/IML loops to read the many data sets. For example, see the article

"Read data sets that are specified by an array of names"

Your  program would look like this (untested):

``````proc iml;
/* load matrices and define modules HERE */

fname = "split1":"split2320";
do i = 1 to ncol(fname);
dsname = "spl1." + strip(fname[i]);
use (dsname);
do t=1 to 120;
g=D[t,1];
read all where(COL2=g) into SS;
LL[i,t]=LLH(1,15,SS);
end;
close;
end;``````

Obsidian | Level 7

Re: The matrix in the modules

thanks for your code, it does work. And one more question, in some loop "t", there is no data read into SS (the reason here is that no COL2 equal to g=D[t,1] in the (dsname)). SS will keep the value of the previous matrix in "t-1" or be reset to invalid value or something else?

Barite | Level 11

Re: The matrix in the modules

When there is no data to read, I think you will get a warning message in the log file and the matrix SS will be undefined.  This will most likely create problems later on, so you need to test for the empty matrix.  For example:

``````if nrow(SS) = 0
then print 'No data found!';
else do;
< do stuff with SS>
end;``````
From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
• 3 replies
• 926 views
• 6 likes
• 3 in conversation