I am trying so run this coding however it get stuck at the Error : (execution) Matrix has not been set to a value. The error is noticed at the statement : ind=(ul[i]-u0)/h; and the system spotted the operation '[' of the operand u1.
Another ERROR: (execution) Invalid subscript or subscript out of range is spotted at the statement : pdh=pdh[2:nrow(pdh),]; and the system spotted the operation '[' of the operands pdh.
The last ERROR: Matrix beta1 has not been set to a value. I wonder that this error is generated due to the previous error spotted in the coding after running it.
I am hoping to get some help on this because i tried my best but cannot figure out is it something that I have missing out or my coding is wrong.
I am using SAS version 9.4 and I have uploaded my input data and my coding is as follow :
proc import out=pepper
datafile='C:\Downloads\Jan05toMay15.xls'
dbms=excel replace;
sheet='Sheet1';
getnames=yes;
run;
proc print data=pepper;
run;
Proc iml;
use pepper;
read all into y;
pdh=j(1,4,999);
print pdh;
APEh=j(4,1,0);
print APEh;
u0=sum(y)/nrow(y);
n=nrow(y);
sum=sum(y);
print sum;
print n;
print u0;
do p=1 to 8;
do d=1 to p;
x0=j(nrow(y),p,0);
do i= p+1 to nrow(y);
x0[i,]=y[i-1:i-p]`;
end;
do h=0.1 to 1 by 0.1;
do j=1 to 4;
t=nrow(y)-(7*j);
n=t-p;
x=j(t,p,0);
u=j(t,1,0);
do i= p+1 to t;
x[i,]=y[i-1:i-p]`;
u[i]=y[i-d];
end;
x1=x[p+1:t,];
u1=u[p+1:t,];
w=j(n,n,0);
w1=j(n,1,0);
x2=j(n,p,1);
do i=1 to t;
ind=(ul[i]-u0)/h;
if (ind<=1) then do;
w[i,i]=(0.75/h)*(1-((u1[i]-u0)*(u1[i]-u0))/(h*h));
w1[i,]=w[i,i];
x2[i,]=x1[i,]*(u1[i]-u0);
end;
else do;
w[i,i]=0;
w1[i,]=w[i,i];
x2[i,]=x1[i,]*(u1[i]-u0);
end;
end;
Xcurl=j(n,2*p,0);
xcurl=xl||x2;
y1=y[p+1:t,];
beta=inv(xcurl`*w*xcurl)*(xcurl`*w*y1);
beta1=beta[1: p,];
yhat=xcurl*beta;
error=y1-yhat;
apeerror=j(7,1,0);
apeerror=error[n-7*j+1:n-7*j+7,];
APEh[j]=(1/7)*apeerror`*apeerror;
end;
APE=sum(APEh)/4;
pdh=pdh//(p||d||h||APE);
end;
end;
end;
pdh=pdh[2:nrow(pdh),];
minAPE=min(pdh[,4]);
do i=1 to nrow(pdh);
if (pdh[i,4]=minAPE) then rw=i;
end;
result=pdh[rw,];
print beta1;
Firstly: Why several threads? 🙂
Secondly, you still have the error of mistyping your u1 vector as ul (with a lower case L).
Thirdly, you still have to take a look at the subscripts in your loops. For instance, you loop from 1 to t in your code and reference u1[i] in the line in which you specify your first error above. However running the following line of code at the end of you IML procedure
print (nrow(u1))[C = 'Rows in u1'] t;
prints the following
which suggests that you have 117 rows in u1, but you are trying to reference the 118'th row. Therefore, I suggest that you take a look at either your loop or the creation of u1.
Hope this can get you in the right direction.
Regards
You have a loop from i=1 to t as below where I have commented where your mistake is
do i=1 to t;
ind=(ul[i]-u0)/h; /* This line should be: ind=(u1[i]-u0)/h; */
if (ind<=1) then do;
w[i,i]=(0.75/h)*(1-((u1[i]-u0)*(u1[i]-u0))/(h*h));
w1[i,]=w[i,i];
x2[i,]=x1[i,]*(u1[i]-u0);
end;
else do;
w[i,i]=0;
w1[i,]=w[i,i];
x2[i,]=x1[i,]*(u1[i]-u0);
end;
end;
Once you have fixed the line draycut is pointing to above, you need to debug the subscript errors. Try inserting the command,
show names;
just before the 1st error, and at other strategic points in your code, this should help you understand what is going wrong. Each time you issue the command you get a lisy of all matrices currently defined together with the number of rows and columns.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.