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

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
ascasfaegADGSgs
Fluorite | Level 6

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;

  

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

You say 

do j=1 to dim(c);

and then refer to c(j+1), That's obviously out of range...

 

PG
ballardw
Super User

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.

ascasfaegADGSgs
Fluorite | Level 6

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;

  

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1571 views
  • 2 likes
  • 3 in conversation