<?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: Replace missing values of one variable with non-missing values of the other variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920387#M362498</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446949"&gt;@Anna_DY&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "missing values" are in fact single periods, preceded by blanks. To help SAS recognize these strings as missing, you can read them with the standard &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n1v0ez0x2x99qdn15797taed37ji.htm" target="_blank" rel="noopener"&gt;$&lt;EM&gt;w&lt;/EM&gt;. informat&lt;/A&gt; and &lt;EM&gt;then&lt;/EM&gt; apply the COALESCEC or MISSING function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
set test;
length NewRate $10;
NewRate = coalescec(&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;input(&lt;/STRONG&gt;&lt;/FONT&gt;Rate1&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;,$10.)&lt;/STRONG&gt;&lt;/FONT&gt;, Rate2);
run;&lt;/PRE&gt;
&lt;P&gt;I have also added a LENGTH statement because otherwise the COALESCEC function would define the length of variable &lt;FONT face="courier new,courier"&gt;NewRate&lt;/FONT&gt;&amp;nbsp;as 200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Mar 2024 09:18:39 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-03-15T09:18:39Z</dc:date>
    <item>
      <title>Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920359#M362479</link>
      <description>&lt;P&gt;I need to replace the missing&amp;nbsp; values in Rate1 with Rate2 ( see attached sample data) . I have tried&amp;nbsp; two&amp;nbsp; ways as below, but none of them worked.&lt;/P&gt;&lt;P&gt;Method 1:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;data test; set test;&lt;/P&gt;&lt;P&gt;NewRate =&amp;nbsp;coalescec(Rate1, Rate2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Method 2:&lt;/P&gt;&lt;P&gt;proc sql; create table test2 as select *,&lt;BR /&gt;case when not missing(RATE1) then Rate1&lt;BR /&gt;else Rate2&lt;BR /&gt;end as NewRate from test order by ID, Date2;&lt;/P&gt;&lt;P&gt;However, Newrate only picked up the values from Rate1, but not&amp;nbsp; Rate2.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 03:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920359#M362479</guid>
      <dc:creator>Anna_DY</dc:creator>
      <dc:date>2024-03-15T03:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920363#M362481</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of attaching a dataset are you able to create sample data for us using datalines?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code you have here should work, I suspect you may have special/non printable characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
	infile datalines dlm=',' missover;
	input Rate1 $ Rate2 $;
	datalines;
abcd123,efgh456
ijkl789,mnop000
	,qrst123
;
run;
	
data test2; 
	set test;
	rate1=compress(rate1,,'kw');
	NewRate = coalescec(Rate1, Rate2);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can you try adding compress to rate1 and see if that fixes your issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 05:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920363#M362481</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-15T05:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920367#M362484</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446949"&gt;@Anna_DY&lt;/a&gt;&amp;nbsp;, you are using coalesce function. "The COALESCE function checks the value of each column in the order in which they are listed and returns the first nonmissing value. " I am not sure if you want to do that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be really great if you can share what you have and what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 05:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920367#M362484</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2024-03-15T05:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920372#M362487</link>
      <description>&lt;P&gt;You should provide actual examples of where your first attempt with Coalescec didn't work. I'm not opening your data set but if the Rate variables are numeric the function should be COALESCE, the Coalescec is for character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, ANY time you test code &lt;STRONG&gt;DO not use the output data set name the same as the input.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When you use:&lt;/P&gt;
&lt;P&gt;data test; set test;&lt;/P&gt;
&lt;P&gt;The Test is completely replaced. So logic errors the first time may have corrupted your data so that you no longer have the same data to attempt to accomplish what you want. Really, in general this code makes it extremely difficult to track down where problems occur. I have seen people use this the same structure replacing the data set in multiple&amp;nbsp;&lt;BR /&gt;Data step blocks and involving Keep and Drop and then asking where their variables went (which had been explicitly dropped in one step and then not kept in another). And since the data was so badly mangled they had to start by rereading the raw source data files again.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 06:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920372#M362487</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-15T06:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920382#M362496</link>
      <description>&lt;P&gt;Please do not attach dataset files.&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;To view your file, I would&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;have to get up from bed &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/LI&gt;
&lt;LI&gt;walk upstairs to my home office&lt;/LI&gt;
&lt;LI&gt;fire up my Mac&lt;/LI&gt;
&lt;LI&gt;download your file&lt;/LI&gt;
&lt;LI&gt;log in to SAS On Demand&lt;/LI&gt;
&lt;LI&gt;upload the file&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;since here, I am on my tablet where I can't use ODA.&lt;/P&gt;
&lt;P&gt;If you provide your dataset as DATA step code with DATALINES, I can read that right here and get a clear picture of your dataset in my mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really store&amp;nbsp;&lt;EM&gt;rates&lt;/EM&gt; as character (because you use COALESCE&lt;STRONG&gt;C&lt;/STRONG&gt;)?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 07:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920382#M362496</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-15T07:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920387#M362498</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446949"&gt;@Anna_DY&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "missing values" are in fact single periods, preceded by blanks. To help SAS recognize these strings as missing, you can read them with the standard &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n1v0ez0x2x99qdn15797taed37ji.htm" target="_blank" rel="noopener"&gt;$&lt;EM&gt;w&lt;/EM&gt;. informat&lt;/A&gt; and &lt;EM&gt;then&lt;/EM&gt; apply the COALESCEC or MISSING function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
set test;
length NewRate $10;
NewRate = coalescec(&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;input(&lt;/STRONG&gt;&lt;/FONT&gt;Rate1&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;,$10.)&lt;/STRONG&gt;&lt;/FONT&gt;, Rate2);
run;&lt;/PRE&gt;
&lt;P&gt;I have also added a LENGTH statement because otherwise the COALESCEC function would define the length of variable &lt;FONT face="courier new,courier"&gt;NewRate&lt;/FONT&gt;&amp;nbsp;as 200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 09:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920387#M362498</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-15T09:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920429#M362507</link>
      <description>&lt;P&gt;Thank you, Jade, It worked perfectly&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 13:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920429#M362507</guid>
      <dc:creator>Anna_DY</dc:creator>
      <dc:date>2024-03-15T13:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920430#M362508</link>
      <description>&lt;P&gt;Thak you for your reply!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 13:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920430#M362508</guid>
      <dc:creator>Anna_DY</dc:creator>
      <dc:date>2024-03-15T13:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values of one variable with non-missing values of the other variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920436#M362509</link>
      <description>&lt;P&gt;Thank you for your advice!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 14:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-of-one-variable-with-non-missing-values/m-p/920436#M362509</guid>
      <dc:creator>Anna_DY</dc:creator>
      <dc:date>2024-03-15T14:01:53Z</dc:date>
    </item>
  </channel>
</rss>

