<?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: Array function with missing condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532006#M145729</link>
    <description>&lt;P&gt;It sounds like you could simplify the DO loop considerably:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=12 to 1 by -1 until (status &amp;gt; .);
   status = aging{i};
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just look backwards through the list and take the first nonmissing value you find.&amp;nbsp; Is that the correct logic?&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 14:19:30 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-01T14:19:30Z</dc:date>
    <item>
      <title>Array function with missing condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/531997#M145722</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some question for assigning value with condition. Given an example below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I create table with missing values at the end of table, which is aging12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input aging aging1 aging2 aging3 aging4 aging5 aging6 aging7 aging8 aging9 aging10 aging11 aging12;
datalines;
1 2 3 4 4 4 4 4 4 4 4 4 4
2 3 4 4 4 4 4 4 4 4 4 3 .
3 4 4 4 4 4 4 4 4 4 2 . .
4 4 4 4 4 4 4 4 4 1 . . .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Next I would like to assign a new column, called status with the latest value available. In the second row, it would be 3, in the third row, it would be 2 and in the last row, it would be 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written down the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set temp;
array aging_a{*} aging1-aging12;

do i=1 to 12;

if cmiss(of aging1--aging12) ne 0 then do;
	if missing(aging_a{i}) then status=aging_a{i-1};
	else status=aging12; 
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output works only the second row and it returns with value equal to 3. However, the rest are returned with missing values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion on this?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/531997#M145722</guid>
      <dc:creator>LengYi</dc:creator>
      <dc:date>2019-02-01T14:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Array function with missing condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532002#M145725</link>
      <description>&lt;P&gt;Not sure what you want as output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By any chance, is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp2;
set temp;
array aging_a{*} aging1-aging12;

do i=1 to 12;

if cmiss(of aging1--aging12) ne 0 then do;
	if missing(aging_a{i}) then do; status=aging_a{i-1};leave;end;
	else status=aging12; 
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532002#M145725</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-01T14:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Array function with missing condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532006#M145729</link>
      <description>&lt;P&gt;It sounds like you could simplify the DO loop considerably:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=12 to 1 by -1 until (status &amp;gt; .);
   status = aging{i};
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just look backwards through the list and take the first nonmissing value you find.&amp;nbsp; Is that the correct logic?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532006#M145729</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-01T14:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Array function with missing condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532011#M145733</link>
      <description>&lt;P&gt;Try this if your missing values are to the end .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
set temp;
array aging_a{*} aging1-aging12;

do i=1 to dim(aging_a);
if aging_a(i)^=. then new_col=aging_a(i);
end;
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532011#M145733</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-02-01T14:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Array function with missing condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532018#M145736</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151001"&gt;@LengYi&lt;/a&gt;&amp;nbsp; Please clarify whether you want the last non missing value as the value of status for records that have at least one missing value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the above assumption of mine is correct, you don't need a loop&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input aging aging1 aging2 aging3 aging4 aging5 aging6 aging7 aging8 aging9 aging10 aging11 aging12;
datalines;
1 2 3 4 4 4 4 4 4 4 4 4 4
2 3 4 4 4 4 4 4 4 4 4 3 .
3 4 4 4 4 4 4 4 4 4 2 . .
4 4 4 4 4 4 4 4 4 1 . . .
;
run;

data want;
set temp;
array aging_a{*} aging12-aging1;
if nmiss(of aging_a{*} )&amp;gt;0 then do;
_iorc_=whichn(coalesce(of aging_a{*}),of aging_a{*});
status=aging_a(_iorc_);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532018#M145736</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-01T14:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Array function with missing condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532036#M145746</link>
      <description>&lt;P&gt;One point using the code structure of&lt;/P&gt;
&lt;PRE&gt;data temp;
set temp;
&lt;/PRE&gt;
&lt;P&gt;can be very dangerous as it completely replaces the source data set with a new data set. An error in logic or even a type could destroy data and require you to go back to early steps to start over. Debugging data issues that occur with this type of code, especially if used repeatedly can sometimes take a great deal of time;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are no "gaps" in the data and you always want the rightmost value of the aging array this would be one way:&lt;/P&gt;
&lt;PRE&gt;data temp2;
set temp;
array aging_a{*} aging1-aging12;
status = aging_a[n(of aging_a(*))];

run;&lt;/PRE&gt;
&lt;P&gt;the N function returns how many of the values are not missing. If there aren't any gaps then that would be the last.&lt;/P&gt;
&lt;P&gt;If there might be gaps it may be more efficient to work from the right to left with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do I = dim(aging_a) to 1 by -1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if not missing (aging_a[I]) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; status= aging_a[I];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LEAVE instruction would exit the do loop when the first non-missing value is find on the right of the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should specify a rule for if the array is empty unless that can never happen.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-function-with-missing-condition/m-p/532036#M145746</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-01T15:21:35Z</dc:date>
    </item>
  </channel>
</rss>

