<?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: Fill in missing values across the arrays using sum ARRAY in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527189#M5243</link>
    <description>&lt;P&gt;It seems like this is what you are asking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array a {10};&lt;/P&gt;
&lt;P&gt;do k=1 to 8;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if a{k) = . then a{k} = sum(a{k+1}, a{k+2});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do k=9 to 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if a{k} . then a{k} = sum{a{k-1}, a{k-2});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop k;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if there's some other variation in the logic that you would like to apply, this should be a good framework to begin.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jan 2019 00:15:23 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-01-15T00:15:23Z</dc:date>
    <item>
      <title>Fill in missing values across the arrays using sum ARRAY</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527188#M5242</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to fill in the missing values across the array by assigning the sum of the previous two columns or the sum of the next two columns.&amp;nbsp; If a1-a3 are missing, then a3=a4+a5.&amp;nbsp; a2=a3+a4, a1=a2+a3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;BR /&gt;input a1-a10;&lt;BR /&gt;datalines;&lt;BR /&gt;. . . 3 4 5 6 7 9 10&lt;BR /&gt;. . 3 4 5 6 7 . . .&lt;BR /&gt;1 2 3 4 5 6 7 . . .&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data WANT;&lt;BR /&gt;input a1-a10;&lt;BR /&gt;datalines;&lt;BR /&gt;17 10 7 3 4 5 6 7 9 10&lt;BR /&gt;10 7 3 4 5 6 7 13 20 33&lt;BR /&gt;1 2 3 4 5 6 7 13 20 33&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a1&amp;nbsp; a2&amp;nbsp; a3 a4 a5 a6 a7 a8&amp;nbsp; a9&amp;nbsp; a10&lt;/P&gt;&lt;P&gt;17&amp;nbsp; 10&amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;10&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;7&amp;nbsp; 13&amp;nbsp; 20&amp;nbsp; 33&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;7&amp;nbsp; 13&amp;nbsp; 20&amp;nbsp; 33&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2019 23:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527188#M5242</guid>
      <dc:creator>smend</dc:creator>
      <dc:date>2019-01-14T23:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in missing values across the arrays using sum ARRAY</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527189#M5243</link>
      <description>&lt;P&gt;It seems like this is what you are asking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array a {10};&lt;/P&gt;
&lt;P&gt;do k=1 to 8;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if a{k) = . then a{k} = sum(a{k+1}, a{k+2});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do k=9 to 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if a{k} . then a{k} = sum{a{k-1}, a{k-2});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop k;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if there's some other variation in the logic that you would like to apply, this should be a good framework to begin.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 00:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527189#M5243</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-15T00:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in missing values across the arrays using sum ARRAY</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527190#M5244</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255229"&gt;@smend&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to fill in the missing values across the array by assigning the sum of the previous two columns or the sum of the next two columns.&amp;nbsp; If a1-a3 are missing, then a3=a4+a5.&amp;nbsp; a2=a3+a4, a1=a2+a3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data example;&lt;BR /&gt;input a1-a10;&lt;BR /&gt;datalines;&lt;BR /&gt;. . . 3 4 5 6 7 9 10&lt;BR /&gt;. . 3 4 5 6 7 . . .&lt;BR /&gt;1 2 3 4 5 6 7 . . .&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data WANT;&lt;BR /&gt;input a1-a10;&lt;BR /&gt;datalines;&lt;BR /&gt;17 10 7 3 4 5 6 7 9 10&lt;BR /&gt;10 7 3 4 5 6 7 13 20 33&lt;BR /&gt;1 2 3 4 5 6 7 13 20 33&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a1&amp;nbsp; a2&amp;nbsp; a3 a4 a5 a6 a7 a8&amp;nbsp; a9&amp;nbsp; a10&lt;/P&gt;
&lt;P&gt;17&amp;nbsp; 10&amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;10&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;7&amp;nbsp; 13&amp;nbsp; 20&amp;nbsp; 33&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;7&amp;nbsp; 13&amp;nbsp; 20&amp;nbsp; 33&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;data want;
   set example;
   array a a1-a10;

   if missing(a1) then do;
      /* find last missing at begining*/
      i=2;
      do while (missing(lastmiss));
         if not missing( a[i]) then lastmiss=i-1;
         i+1;
      end;
      do i= lastmiss to 1 by -1;
         a[i]= sum(a[i+1],a[i+2]);
      end;
   end;
   if missing(a10) then do;
      /* find first missing at end*/
      i=9;
      do while(missing(firstmiss));
         if not missing(a[i]) then firstmiss=i+1;
         i=i-1;
      end;
      do i=firstmiss to 10;
         a[i]=sum(a[i-2],a[i-1]);
      end;
    
   end;
   drop i firstmiss lastmiss;
run;&lt;/PRE&gt;
&lt;P&gt;This will fail if you only have one value at either end (A1 or A10), will not do anything for missing in the middle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will fail if there are not 2 sequential values with values.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 00:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527190#M5244</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-15T00:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in missing values across the arrays using sum ARRAY</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527201#M5245</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data example;
input a1-a10;
datalines;
. . . 3 4 5 6 7 9 10
. . 3 4 5 6 7 . . .
1 2 3 4 5 6 7 . . .
;
run;
data want;
set example;
array t(*) a1-a10;
array r(*) a10-a1;
j=whichn(coalesce(of t(*)),of t(*));
k=whichn(coalesce(of r(*)),of r(*));
if j&amp;gt;1 then
do i=j-1 by -1 to 1;
t(i)=sum(t(i+1),t(i+2))	;
end;
if k&amp;gt;1 then
do i=k-1 by -1 to 1;
r(i)=sum(r(i+1),r(i+2))	;
end;
keep a:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jan 2019 02:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527201#M5245</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-15T02:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in missing values across the arrays using sum ARRAY</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527234#M5252</link>
      <description>&lt;P&gt;There are too many scenario you need to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input a1-a10;
datalines;
. . . 3 4 5 6 7 9 10
. . 3 4 5 6 7 . . .
1 2 3 4 5 6 7 . . .
;
run;

data want;
 set example;
 array x{*} a:;
if missing(x{1}) then do;
 do i=1 to dim(x);
   if not missing(x{i}) then leave;
 end;
 do j=i-1 to 1 by -1;
   x{j}=x{j+2}+x{j+1};
 end;
end;

d=dim(x);
if missing(x{d}) then do;
  do i=dim(x) to 1 by -1;
   if not missing(x{i}) then leave;
 end;
 do j=i+1 to d;
   x{j}=x{j-2}+x{j-1};
 end;
end;
drop i j d;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jan 2019 08:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/527234#M5252</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-15T08:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in missing values across the arrays using sum ARRAY</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/540541#M7233</link>
      <description>Thank you for you feedback.</description>
      <pubDate>Tue, 05 Mar 2019 18:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-missing-values-across-the-arrays-using-sum-ARRAY/m-p/540541#M7233</guid>
      <dc:creator>smend</dc:creator>
      <dc:date>2019-03-05T18:51:48Z</dc:date>
    </item>
  </channel>
</rss>

