<?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: Comparing fields in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241461#M44755</link>
    <description>&lt;P&gt;Using the RANGE function which accepts missing values but ignores them might do the trick, both in the data step or SQL version of the solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combined;
input a b c d e;
datalines;
123	. 	123	123	123
456	111	456	. 	456
685	789	789	789	789
. 	. 	254	987	987
;

data want;
array ne{4} ne_a ne_b ne_c ne_d;
array col{4} a b c d;
set combined end=done;
do i = 1 to 4;
    if range(col{i},e) ne 0 then ne{i} + 1;
    end;
if done then output;
keep ne_:;
run;

proc print data=want noobs; run;

proc sql;
select 
    sum(range(a,e) ne 0) as ne_a,
    sum(range(b,e) ne 0) as ne_b,
    sum(range(c,e) ne 0) as ne_c,
    sum(range(d,e) ne 0) as ne_d
from combined;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 01 Jan 2016 03:40:18 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-01-01T03:40:18Z</dc:date>
    <item>
      <title>Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241435#M44748</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking for some insight/direction on the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 5 columns of data, A-E. I want to compare column E with columns A-D and count&amp;nbsp;where they are not equal for all rows. However, columns A-D may have the same record in one or more columns, or might contain a missing record that I don't want to count.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've started with a string of proc sql statements as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table one as
select count (*)
from combined
where A = E and A not in (' ');

create table two as
select count(*)
from (select * from combined where A &amp;lt;&amp;gt; B and B not in (' '))
where B = E;

create table three as
select count(*)
from (select * from combined where A &amp;lt;&amp;gt; C and C not in (' '))
where C = E;

create table four as
select count(*)
from (select * from combined where A &amp;lt;&amp;gt; D and D not in (' '))
where D = E;

quit;
&lt;/PRE&gt;
&lt;P&gt;However, when I QA some of these results I see that I'm counting records that I shouldnt across some of the latter tables. I've played around with adding some additional exclusion criteria but I can't seem to get it right. I think their is an easier way to compare the data in these columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any thoughts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy New Year!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 21:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241435#M44748</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2015-12-31T21:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241436#M44749</link>
      <description>&lt;P&gt;It would help us see what you are attempting if you provide some example input data, which should demonstrate all of the types of cases you might expect, no match, one match, 2 matches , 3 matches, 4 matches And what the outcome for that example data should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if this is to generate a report of some sort what the final report might look like as the counting may well be best done in one of the report procedures.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 21:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241436#M44749</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-31T21:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241445#M44751</link>
      <description>&lt;P&gt;Here is some example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="5" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl63" style="height: 15.0pt; width: 48pt;"&gt;A&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;B&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;C&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;D&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;E&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;123&lt;/TD&gt;
&lt;TD class="xl63"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl63"&gt;123&lt;/TD&gt;
&lt;TD class="xl63"&gt;123&lt;/TD&gt;
&lt;TD class="xl63"&gt;123&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;456&lt;/TD&gt;
&lt;TD class="xl63"&gt;111&lt;/TD&gt;
&lt;TD class="xl63"&gt;456&lt;/TD&gt;
&lt;TD class="xl63"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl63"&gt;456&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;685&lt;/TD&gt;
&lt;TD class="xl63"&gt;789&lt;/TD&gt;
&lt;TD class="xl63"&gt;789&lt;/TD&gt;
&lt;TD class="xl63"&gt;789&lt;/TD&gt;
&lt;TD class="xl63"&gt;789&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl63"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl63"&gt;254&lt;/TD&gt;
&lt;TD class="xl63"&gt;987&lt;/TD&gt;
&lt;TD class="xl63"&gt;987&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first sql statement would show a count in table one but&amp;nbsp;not for any of the other tables (because B is missing and C,D = E).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second sql statement would show a count for table one and table two but not three and four (because C=A and D is missing).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The third sql statement would show a count in table one and two but not three and four (because C,D = E).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fourth sql statement would show a count in table three and four but not one or two (because A,B are null).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to do some analysis on a much larger data set. At this point I'm just looking at totals for these conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 22:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241445#M44751</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2015-12-31T22:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241449#M44752</link>
      <description>Since you are not satisfied with your current SQL, and don't really understand your desired outcome, it would be great if you could post the corresponding desired output/report.</description>
      <pubDate>Thu, 31 Dec 2015 22:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241449#M44752</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-12-31T22:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241450#M44753</link>
      <description>&lt;P&gt;That's a fair example of an input set. I note there are no rows without at least one&amp;nbsp;match for E.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the desired output in a similar tabular form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that a datastep may be more efficient than your current sql approach as all of the individual comparisons could be done in one pass. But what that desired output might be ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also generally having different cases in different datasets makes analysis more complicated.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 22:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241450#M44753</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-31T22:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241458#M44754</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/29074"&gt;@Ody&lt;/a&gt; wrote:&lt;BR /&gt;&amp;nbsp;
&lt;P&gt;I have 5 columns of data, A-E. I want to compare column E with columns A-D and count&amp;nbsp;where they are not equal for all rows. However, columns A-D may have the same record in one or more columns, or might contain a missing record that I don't want to count.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One quick way to compare columns of data to check if all match is to see if the min/max of the rows are the same.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general I think that array processing within a data step is the way you'll want to go. &amp;nbsp;The Min/Max function ignore missing values, but if you want some other criteria you'll have to expand on your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array vals(*) a b c d e;&lt;/P&gt;
&lt;P&gt;retain count;&lt;/P&gt;
&lt;P&gt;if min(of vals(*)) ne max(of vals(*)) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;flag=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;count+1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else flag=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if flag=1 then do;&lt;/P&gt;
&lt;P&gt;*go through some process to identify the issues;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 23:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241458#M44754</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-31T23:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241461#M44755</link>
      <description>&lt;P&gt;Using the RANGE function which accepts missing values but ignores them might do the trick, both in the data step or SQL version of the solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combined;
input a b c d e;
datalines;
123	. 	123	123	123
456	111	456	. 	456
685	789	789	789	789
. 	. 	254	987	987
;

data want;
array ne{4} ne_a ne_b ne_c ne_d;
array col{4} a b c d;
set combined end=done;
do i = 1 to 4;
    if range(col{i},e) ne 0 then ne{i} + 1;
    end;
if done then output;
keep ne_:;
run;

proc print data=want noobs; run;

proc sql;
select 
    sum(range(a,e) ne 0) as ne_a,
    sum(range(b,e) ne 0) as ne_b,
    sum(range(c,e) ne 0) as ne_c,
    sum(range(d,e) ne 0) as ne_d
from combined;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Jan 2016 03:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241461#M44755</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-01T03:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241658#M44804</link>
      <description>&lt;P&gt;Thanks for the feedback and suggestions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll have to give this some more thought and maybe come up with a better approach.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2016 14:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241658#M44804</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2016-01-04T14:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241695#M44811</link>
      <description>I was able to complete the comparison I wanted to do by creating separate tables for the individual number fields and stacking them vertically to compare (vs the horizontal approach I was trying to do earlier).&lt;BR /&gt;&lt;BR /&gt;Just fyi, thanks again for the feedback.</description>
      <pubDate>Mon, 04 Jan 2016 18:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-fields/m-p/241695#M44811</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2016-01-04T18:05:37Z</dc:date>
    </item>
  </channel>
</rss>

