<?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: coalesce function in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868015#M42703</link>
    <description>&lt;P&gt;Note that the MISSING option control what character SAS prints for a missing numeric value.&lt;/P&gt;
&lt;P&gt;Try running this code with different characters for the MISSING option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';
data test;
  input num;
  string1 = put(num,8.);
  string2 = coalescec(string1,'default');
cards;
100
.
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also notice that in a data step you have to use the &lt;STRONG&gt;coalesceC()&lt;/STRONG&gt; function to coalesce character values.&amp;nbsp; If you use coalesce() function instead then SAS will convert try to convert both character values to numeric.&lt;/P&gt;
&lt;PRE&gt;1428  options missing=' ';
1429  data test;
1430    input num;
1431    string1 = put(num,8.);
1432    string2 = coalesce(string1,'default');
1433  cards;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1432:22   1432:30
NOTE: Invalid numeric data, 'default' , at line 1432 column 30.
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1434        100
num=100 string1=100 string2=100 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, 'default' , at line 1432 column 30.
1435        .
num= string1=  string2= _ERROR_=1 _N_=2
NOTE: The data set WORK.TEST has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2023 16:00:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-04T16:00:03Z</dc:date>
    <item>
      <title>coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/867997#M42694</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When there is a value for cf_client, I would like extRef to be equal to that value otherwise, it should be equal to the value client.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's wrong in the script below ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   input client $ cf_client;
   datalines;
235987 .
236663 .
236900 .
237009 125
237720 .
237744 .
;

Data test2;
set test;
cf2_client=put(cf_client,8.);
extRef=coalescec(cf2_client,client);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 14:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/867997#M42694</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-04-04T14:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/867999#M42695</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When there is a value for cf_client, I would like extRef to be equal to that value otherwise, it should be equal to the value client.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's wrong in the script below ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   input client $ cf_client;
   datalines;
235987 .
236663 .
236900 .
237009 125
237720 .
237744 .
;

Data test2;
set test;
cf2_client=put(cf_client,8.);
extRef=coalescec(cf2_client,client);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;CF2_CLIENT is never missing. CF2_CLIENT is a character variable, and when it has the value &lt;FONT face="courier new,courier"&gt;'.'&lt;/FONT&gt; this is not a missing value for a character variable. Instead, &lt;FONT face="courier new,courier"&gt;' '&lt;/FONT&gt; (a single blank space) is a missing value for a character variable. So&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
    set test;
    if not missing(cf_client) then cf2_client=put(cf_client,8.);
    extRef=coalescec(cf2_client,client);
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>Tue, 04 Apr 2023 14:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/867999#M42695</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T14:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868004#M42696</link>
      <description>&lt;P&gt;Please note that the second variable cf_client, is numerical, that this variable is empty, except in one place where the value equal 125.&amp;nbsp; Then I convert this variable into a new one cf2_client as string variable.&amp;nbsp; Then I wish to use the coalescec function by comparing two string variable.&amp;nbsp; When the first value is empty it takes the second one and assign it to extRef.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will it change something in your script ?&lt;/P&gt;
&lt;P&gt;Why the coalesce function seems to see something in cf2_client when it is empty ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868004#M42696</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-04-04T15:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868005#M42697</link>
      <description>&lt;P&gt;Re-read what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then answer this question&lt;/P&gt;
&lt;LI-SPOILER&gt;Does the string &lt;FONT face="courier new,courier"&gt;'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.'&lt;/FONT&gt; equal the string &lt;FONT face="courier new,courier"&gt;'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'&lt;/FONT&gt;?&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868005#M42697</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-04T15:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868006#M42698</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why the coalesce function seems to see something in cf2_client when it is empty ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I explained this already. CF2_CLIENT is never empty or missing. It contains a dot for most records, this is not a missing value for a character variable.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868006#M42698</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T15:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868008#M42699</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    infile DATALINES MISSOVER;
	input client $ cf_client;
	DATALINES;
235987   
236663  
236900  
237009 125
237720  
237744  
;

data test2;
    set test;
    cf2_client=put(cf_client,8.);
    extRef=coalescec(cf2_client,client);
run;

data test3;
    set test;
    if not missing(cf_client) then cf2_client=put(cf_client,8.);
    extRef=coalescec(cf2_client,client);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, I believe that cf_client contains missing data and when cf_client is missing, it can't convert it to an empty string. Is it the case.&amp;nbsp; put(empty var, 8.) is equal to what ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868008#M42699</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-04-04T15:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868011#M42700</link>
      <description>no&lt;BR /&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868011#M42700</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-04-04T15:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868014#M42702</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;Now, I believe that cf_client contains missing data and when cf_client is missing, it can't convert it to an empty string. Is it the case.&amp;nbsp; put(empty var, 8.) is equal to what ?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you check the data set created and what happened?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868014#M42702</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-04T15:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868015#M42703</link>
      <description>&lt;P&gt;Note that the MISSING option control what character SAS prints for a missing numeric value.&lt;/P&gt;
&lt;P&gt;Try running this code with different characters for the MISSING option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';
data test;
  input num;
  string1 = put(num,8.);
  string2 = coalescec(string1,'default');
cards;
100
.
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also notice that in a data step you have to use the &lt;STRONG&gt;coalesceC()&lt;/STRONG&gt; function to coalesce character values.&amp;nbsp; If you use coalesce() function instead then SAS will convert try to convert both character values to numeric.&lt;/P&gt;
&lt;PRE&gt;1428  options missing=' ';
1429  data test;
1430    input num;
1431    string1 = put(num,8.);
1432    string2 = coalesce(string1,'default');
1433  cards;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1432:22   1432:30
NOTE: Invalid numeric data, 'default' , at line 1432 column 30.
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1434        100
num=100 string1=100 string2=100 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, 'default' , at line 1432 column 30.
1435        .
num= string1=  string2= _ERROR_=1 _N_=2
NOTE: The data set WORK.TEST has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868015#M42703</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-04T16:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868021#M42706</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    infile DATALINES MISSOVER;
	input client $ cf_client;
	DATALINES;
235987   
236663  
236900  
237009 125
237720  
237744  
;

data test2;
    set test;
    cf2_client=put(cf_client,8.);
    extRef=coalescec(cf2_client,client);
run;

data test3;
    set test;
    if not missing(cf_client) then cf2_client=put(cf_client,8.);
    extRef=coalescec(cf2_client,client);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, I believe that cf_client contains missing data and when cf_client is missing, it can't convert it to an empty string. Is it the case.&amp;nbsp; put(empty var, 8.) is equal to what ?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I find these sentences very confusing. I am not "convert(ing) it to an empty string". I am creating a new variable which has non-missing value when the IF condition is satisfied, and missing value when the IF condition is not satisfied. I have no idea what the part about "put(empty var 8.)" means or how it is relevant.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/coalesce-function/m-p/868021#M42706</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T16:28:28Z</dc:date>
    </item>
  </channel>
</rss>

