<?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: Fill a column with values from other columns only if they match and are not null in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430399#M106386</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array vars{*} var:;
var_out = '___                          ';
/* use enough blanks to accomodate the maximum length of your vars */
do i = 1 to dim(vars);
  if vars{i} ne ''
  then do;
    if var_out = '___' then var_out = vars{i};
    else if vars{i} ne var_out then var_out = '';
  end;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2018 13:08:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-01-24T13:08:18Z</dc:date>
    <item>
      <title>Fill a column with values from other columns only if they match and are not null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430390#M106384</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with columns that should contain the same data acquired from other tables, with this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;var1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;var2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;var3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;var4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;output&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;car&lt;/TD&gt;&lt;TD&gt;car&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;car&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;car&lt;/TD&gt;&lt;TD&gt;truck&lt;/TD&gt;&lt;TD&gt;car&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;truck&lt;/TD&gt;&lt;TD&gt;truck&lt;/TD&gt;&lt;TD&gt;truck&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;truck&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;car&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;car&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example var1 to var4 contain the same string information from different sources, now I want to create the output column to the right that contains the value if it's the same for var1 to var4 only and ignores columns where the value is missing. If the values in var1 to var4 are inconsistent like in the second row it should leave the output variable empty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can think of a way using SQL and CASE but it would require writing out all the combinations, with the risk of missing some. Is there a quicker way to compare the vales in different columns but ignoring empty cells?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 12:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430390#M106384</guid>
      <dc:creator>bouz22</dc:creator>
      <dc:date>2018-01-24T12:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Fill a column with values from other columns only if they match and are not null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430399#M106386</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array vars{*} var:;
var_out = '___                          ';
/* use enough blanks to accomodate the maximum length of your vars */
do i = 1 to dim(vars);
  if vars{i} ne ''
  then do;
    if var_out = '___' then var_out = vars{i};
    else if vars{i} ne var_out then var_out = '';
  end;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 13:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430399#M106386</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-24T13:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fill a column with values from other columns only if they match and are not null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430414#M106388</link>
      <description>&lt;P&gt;Thank you for the quick reply. it works! This is something I would have never come up with...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks, I was stuck on this already for quite a while.&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>Wed, 24 Jan 2018 13:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-a-column-with-values-from-other-columns-only-if-they-match/m-p/430414#M106388</guid>
      <dc:creator>bouz22</dc:creator>
      <dc:date>2018-01-24T13:34:32Z</dc:date>
    </item>
  </channel>
</rss>

