<?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: Alternative function for extract non missing value from two column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692603#M211011</link>
    <description>&lt;P&gt;I use the function but why I am not getting correct output. Code for reference.&lt;/P&gt;
&lt;PRE&gt;data new;
input id1 id2 $;
cards;
1 11.7
2 .
. 3-4.5
. .
. abc
7 .
;
run;
data new1;
set new;
id1_=put(id1,8.);
X=coalescec(id1_, id2);
run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Oct 2020 15:37:28 GMT</pubDate>
    <dc:creator>dash</dc:creator>
    <dc:date>2020-10-19T15:37:28Z</dc:date>
    <item>
      <title>Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692590#M211005</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to find non missing value between col id1 and id2 and then place it in variable x like below.&lt;/P&gt;
&lt;P&gt;Is there any alternative function to solve this if more variables are there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data new;
input id1 id2 $;
cards;
1 11
2 .
. 3
. .
. abc
7 .
;
run;
data new1;
set new;
if id1 eq . then x=id2;
else if id1 ne . then x=id1;
else x=.;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2020 15:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692590#M211005</guid>
      <dc:creator>dash</dc:creator>
      <dc:date>2020-10-19T15:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692591#M211006</link>
      <description>&lt;P&gt;Use the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1vjttz6nuankzn1gh4z3wgcu0bf.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;COALESCE&lt;/A&gt;&amp;nbsp;function.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 15:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692591#M211006</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-19T15:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692600#M211009</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19789"&gt;@dash&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to find non missing value between col id1 and id2 and then place it in variable x like below.&lt;/P&gt;
&lt;P&gt;Is there any alternative function to solve this if more variables are there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data new;
input id1 id2 $;
cards;
1 11
2 .
. 3
. .
. abc
7 .
;
run;
data new1;
set new;
if id1 eq . then x=id2;
else if id1 ne . then x=id1;
else x=.;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So is your X variable supposed to be numeric or character? This is very important since you are starting with one of each. The character value 'abc' cannot be stored in a numeric.&lt;/P&gt;
&lt;P&gt;Any time you let the automatic conversion of numeric to character occur you have a chance of getting unexpected results. So consideration of how the create the character version of "id1" needs some consideration.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 15:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692600#M211009</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-19T15:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692602#M211010</link>
      <description>&lt;P&gt;coalesceC()&lt;/P&gt;
&lt;P&gt;and/or CATT() functions will do what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that coalesceC (added C) has to be used with character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19789"&gt;@dash&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to find non missing value between col id1 and id2 and then place it in variable x like below.&lt;/P&gt;
&lt;P&gt;Is there any alternative function to solve this if more variables are there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data new;
input id1 id2 $;
cards;
1 11
2 .
. 3
. .
. abc
7 .
;
run;
data new1;
set new;
if id1 eq . then x=id2;
else if id1 ne . then x=id1;
else x=.;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 15:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692602#M211010</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-19T15:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692603#M211011</link>
      <description>&lt;P&gt;I use the function but why I am not getting correct output. Code for reference.&lt;/P&gt;
&lt;PRE&gt;data new;
input id1 id2 $;
cards;
1 11.7
2 .
. 3-4.5
. .
. abc
7 .
;
run;
data new1;
set new;
id1_=put(id1,8.);
X=coalescec(id1_, id2);
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2020 15:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692603#M211011</guid>
      <dc:creator>dash</dc:creator>
      <dc:date>2020-10-19T15:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692621#M211019</link>
      <description>Can anyone help me why coalescec function is not working in the newly provided dataset</description>
      <pubDate>Mon, 19 Oct 2020 16:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692621#M211019</guid>
      <dc:creator>dash</dc:creator>
      <dc:date>2020-10-19T16:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative function for extract non missing value from two column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692623#M211020</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19789"&gt;@dash&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Can anyone help me why coalescec function is not working in the newly provided dataset&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id1_=put(id1,8.);&lt;/P&gt;
&lt;P&gt;unconditionally. So the value of id1_ is "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .", 7 blanks and a dot by default when id1 is missing. So there is ALWAYS a value for Id_1 and that is the result.&lt;/P&gt;
&lt;P&gt;Perhaps:&lt;/P&gt;
&lt;PRE&gt;data new1;
   set new;
   if not missing(id1) then id1_=put(id1,8. -L);
   X=coalescec(id1_, id2);
run;&lt;/PRE&gt;
&lt;P&gt;Best practice would be to specify a length for X before first use, otherwise length may not hold all the values you need.&lt;/P&gt;
&lt;P&gt;The -L in the Put for Id1 results in left justified text, which may be nicer for output when the result is the Id1_ value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 16:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-function-for-extract-non-missing-value-from-two/m-p/692623#M211020</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-19T16:56:09Z</dc:date>
    </item>
  </channel>
</rss>

