<?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 Set new Variable as the non-missing value in an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-new-Variable-as-the-non-missing-value-in-an-array/m-p/597670#M172233</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set in this form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id x1-x5;
	datalines;
1 3 . . . . 
2 . 2 . . .
3 . . 5 . . 
4 . . . 7 .
5 . . . . 7
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm trying to use an array that will create a new variable to the non-missing value. I want my new variable to look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x_new&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My do loop is only selecting the final value (x5), how do I get it to select the non-missing.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2019 10:39:27 GMT</pubDate>
    <dc:creator>MB_Analyst</dc:creator>
    <dc:date>2019-10-18T10:39:27Z</dc:date>
    <item>
      <title>Set new Variable as the non-missing value in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-new-Variable-as-the-non-missing-value-in-an-array/m-p/597670#M172233</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set in this form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id x1-x5;
	datalines;
1 3 . . . . 
2 . 2 . . .
3 . . 5 . . 
4 . . . 7 .
5 . . . . 7
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm trying to use an array that will create a new variable to the non-missing value. I want my new variable to look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x_new&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My do loop is only selecting the final value (x5), how do I get it to select the non-missing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 10:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-new-Variable-as-the-non-missing-value-in-an-array/m-p/597670#M172233</guid>
      <dc:creator>MB_Analyst</dc:creator>
      <dc:date>2019-10-18T10:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Set new Variable as the non-missing value in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-new-Variable-as-the-non-missing-value-in-an-array/m-p/597675#M172234</link>
      <description>&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1vjttz6nuankzn1gh4z3wgcu0bf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Coalesce Function&lt;/A&gt; like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id x1-x5;
	datalines;
1 3 . . . . 
2 . 2 . . .
3 . . 5 . . 
4 . . . 7 .
5 . . . . 7
;

data want(keep=id xnew);
    set have;
    xnew=coalesce(of x1-x5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id  xnew
1	3
2	2
3	5
4	7
5	7&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 10:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-new-Variable-as-the-non-missing-value-in-an-array/m-p/597675#M172234</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-18T10:56:54Z</dc:date>
    </item>
  </channel>
</rss>

