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();
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;
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;
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?
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.