<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need help with looping through array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269271#M53338</link>
    <description>&lt;P&gt;Are you looking for something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let LAG = 4;
%let cmax = 0.9;
%let cmin = 0.3;
%let cvalue = (&amp;amp;cmax.-&amp;amp;cmin.)/(&amp;amp;LAG.-1);
data tACVF;
   array ACVF(&amp;amp;LAG.);
   array c(&amp;amp;LAG.);	
   /* initialize C array*/
   do i=1 to dim(c);
      c(i)=&amp;amp;cmax.-(&amp;amp;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That has all the values in one record.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Mon, 09 May 2016 20:12:14 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-05-09T20:12:14Z</dc:date>
    <item>
      <title>Need help with looping through array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269224#M53327</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have these equations (as an example):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ACVF1=c1+c1*c2+c2*c3+c3*c4;&lt;BR /&gt;ACVF2=c2+c1*c3+c2*c4;&lt;BR /&gt;ACVF3=c3+c1*c4;&lt;BR /&gt;ACVF4=c4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to &lt;SPAN&gt;fulfill&lt;/SPAN&gt; them&amp;nbsp;in general to be able to calculate various LAG&amp;nbsp;autocorrelation's&amp;nbsp;for ma(q) process.&lt;/P&gt;&lt;P&gt;Here is what I have accomplished so far:&lt;/P&gt;&lt;PRE&gt;%let LAG = 4;
%let cmax = 0.9;
%let cmin = 0.3;
%let cvalue = (&amp;amp;cmax.-&amp;amp;cmin.)/(&amp;amp;LAG.-1);
data tACVF;
	array ACVF(&amp;amp;LAG.);
	array c(&amp;amp;LAG.);	
	do i=1 to dim(c);
		c(i)=&amp;amp;cmax.-(&amp;amp;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;&lt;/PRE&gt;&lt;P&gt;I'm getting this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: Array subscript out of range at line 66 column 22.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;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 ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2016 16:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269224#M53327</guid>
      <dc:creator>ascasfaegADGSgs</dc:creator>
      <dc:date>2016-05-09T16:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with looping through array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269231#M53329</link>
      <description>&lt;P&gt;You say&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;do j=1 to dim(c);&lt;/PRE&gt;
&lt;P&gt;and then refer to c(j+1), That's obviously out of range...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2016 17:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269231#M53329</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-09T17:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with looping through array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269271#M53338</link>
      <description>&lt;P&gt;Are you looking for something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let LAG = 4;
%let cmax = 0.9;
%let cmin = 0.3;
%let cvalue = (&amp;amp;cmax.-&amp;amp;cmin.)/(&amp;amp;LAG.-1);
data tACVF;
   array ACVF(&amp;amp;LAG.);
   array c(&amp;amp;LAG.);	
   /* initialize C array*/
   do i=1 to dim(c);
      c(i)=&amp;amp;cmax.-(&amp;amp;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That has all the values in one record.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2016 20:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269271#M53338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-09T20:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with looping through array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269449#M53379</link>
      <description>&lt;P&gt;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!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let LAG = 4;
%let cmax = 0.9;
%let cmin = 0.3;
%let cvalue = (&amp;amp;cmax.-&amp;amp;cmin.)/(&amp;amp;LAG.-1);
data tACVF;
	array ACVF(&amp;amp;LAG.);
	array c(&amp;amp;LAG.);	
	/* initialize C array*/
	do i=1 to dim(c);
		c(i)=&amp;amp;cmax.-(&amp;amp;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;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 15:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-looping-through-array/m-p/269449#M53379</guid>
      <dc:creator>ascasfaegADGSgs</dc:creator>
      <dc:date>2016-05-10T15:30:22Z</dc:date>
    </item>
  </channel>
</rss>

