Hi,
I have these equations (as an example):
ACVF1=c1+c1*c2+c2*c3+c3*c4;
ACVF2=c2+c1*c3+c2*c4;
ACVF3=c3+c1*c4;
ACVF4=c4;
I need to fulfill them in general to be able to calculate various LAG autocorrelation's for ma(q) process.
Here is what I have accomplished so far:
%let LAG = 4; %let cmax = 0.9; %let cmin = 0.3; %let cvalue = (&cmax.-&cmin.)/(&LAG.-1); data tACVF; array ACVF(&LAG.); array c(&LAG.); do i=1 to dim(c); c(i)=&cmax.-(&cvalue.*(i-1)); ACVF(i)=c(i); do j=1 to dim(c); ACVF(j)=ACVF(j)+c(i)*c(j+1); output; end; end; proc print; run;
I'm getting this:
ERROR: Array subscript out of range at line 66 column 22.
I assume this is because of reaching higher index then there is, but I don't know how to solve this issue. Can anyone help ?
That's a bit closer to what I wanted to achieve, but you gave me an idea on how to solve my issue here. Many thanks!
Here's the code:
%let LAG = 4; %let cmax = 0.9; %let cmin = 0.3; %let cvalue = (&cmax.-&cmin.)/(&LAG.-1); data tACVF; array ACVF(&LAG.); array c(&LAG.); /* initialize C array*/ do i=1 to dim(c); c(i)=&cmax.-(&cvalue.*(i-1)); end; do k=1 to dim(Acvf); ACVF(k)=c(k); do j=1 to (dim(c)-k); s=j+k; ACVF(k)=sum(ACVF(k),c(j)*c(s)); end; /* possible output here*/ end; proc print; run;
You say
do j=1 to dim(c);
and then refer to c(j+1), That's obviously out of range...
Are you looking for something like this:
%let LAG = 4;
%let cmax = 0.9;
%let cmin = 0.3;
%let cvalue = (&cmax.-&cmin.)/(&LAG.-1);
data tACVF;
array ACVF(&LAG.);
array c(&LAG.);
/* initialize C array*/
do i=1 to dim(c);
c(i)=&cmax.-(&cvalue.*(i-1));
end;
do k=1 to dim(Acvf);
ACVF(k)=c(k);
do j=k to (dim(c)-1);
ACVF(j)=sum(ACVF(j),c(j)*c(j+1));
end;
/* possible output here*/
end;
run;
That has all the values in one record.
If you are looking for triangle of values for ACVF then use the location indicated for the output. Your original output statement was going to create possibly more records than you really wanted as you had intermediate values of the ACVF. Drop the i, j, k if desired.
That's a bit closer to what I wanted to achieve, but you gave me an idea on how to solve my issue here. Many thanks!
Here's the code:
%let LAG = 4; %let cmax = 0.9; %let cmin = 0.3; %let cvalue = (&cmax.-&cmin.)/(&LAG.-1); data tACVF; array ACVF(&LAG.); array c(&LAG.); /* initialize C array*/ do i=1 to dim(c); c(i)=&cmax.-(&cvalue.*(i-1)); end; do k=1 to dim(Acvf); ACVF(k)=c(k); do j=1 to (dim(c)-k); s=j+k; ACVF(k)=sum(ACVF(k),c(j)*c(s)); end; /* possible output here*/ end; proc print; run;
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.