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;

  

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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