<?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: Field comparison in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482460#M286866</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input field_1 : $20.	field_2	:$20.;
a=translate(field_1,'|',',');
b=translate(field_2,'|',',');
x1=prxchange(cats('s/',b,'//'),-1,translate(field_1,' ',','));
x2=prxchange(cats('s/',a,'//'),-1,translate(field_2,' ',','));

want=catx(' ',x1,x2);
drop a b x1 x2;
cards;
003,004,006    003,004
002,003,005     002,005
003,004        003,004,006
002,005      002,003,005
;
run;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Jul 2018 13:30:44 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-07-30T13:30:44Z</dc:date>
    <item>
      <title>Field comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482430#M286862</link>
      <description>&lt;P&gt;I am trying to compare two fields and output the difference. Please see below example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;field_1&lt;/TD&gt;&lt;TD&gt;field_2&lt;/TD&gt;&lt;TD&gt;results&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;003,004,006&lt;/TD&gt;&lt;TD&gt;003,004&lt;/TD&gt;&lt;TD&gt;006&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;002,003,005&lt;/TD&gt;&lt;TD&gt;002,005&lt;/TD&gt;&lt;TD&gt;003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;003,004&lt;/TD&gt;&lt;TD&gt;003,004,006&lt;/TD&gt;&lt;TD&gt;006&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;002,005&lt;/TD&gt;&lt;TD&gt;002,003,005&lt;/TD&gt;&lt;TD&gt;003&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 11:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482430#M286862</guid>
      <dc:creator>Sir_Lancelot</dc:creator>
      <dc:date>2018-07-30T11:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Field comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482438#M286863</link>
      <description>&lt;P&gt;Will it always be like that, i.e. field_2 as a subet of field_1?&amp;nbsp; If so:&lt;/P&gt;
&lt;PRE&gt;results=strip(tranwrd(field_1,field_2,""));&lt;/PRE&gt;
&lt;P&gt;If not then you will need to loop through then:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  do i=1 to countw(field_2,",");
    if findw(field_1,scan(field_2,i,","),",") then results=scan(field_2,i,",");
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note that this only assumes one difference, other wise you will need:&lt;/P&gt;
&lt;PRE&gt;    if findw(field_1,scan(field_2,i,","),",") then results=catx(",",results,scan(field_2,i,","));
&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Jul 2018 12:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482438#M286863</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-30T12:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Field comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482454#M286864</link>
      <description>&lt;P&gt;Do I need a cup of coffee, or should the FINDW result be compared to 0?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 13:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482454#M286864</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-30T13:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Field comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482456#M286865</link>
      <description>&lt;P&gt;I would have tea myself.&amp;nbsp; But yes, I was going with the reverse mistakenly.&amp;nbsp; You can either compare with zero or not() it:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  do i=1 to countw(field_2,",");
    if not(findw(field_1,scan(field_2,i,","),",")) then results=scan(field_2,i,",");
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Jul 2018 13:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482456#M286865</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-30T13:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Field comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482460#M286866</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input field_1 : $20.	field_2	:$20.;
a=translate(field_1,'|',',');
b=translate(field_2,'|',',');
x1=prxchange(cats('s/',b,'//'),-1,translate(field_1,' ',','));
x2=prxchange(cats('s/',a,'//'),-1,translate(field_2,' ',','));

want=catx(' ',x1,x2);
drop a b x1 x2;
cards;
003,004,006    003,004
002,003,005     002,005
003,004        003,004,006
002,005      002,003,005
;
run;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Jul 2018 13:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482460#M286866</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-30T13:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Field comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482479#M286867</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214844"&gt;@Sir_Lancelot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to compare two fields and output the difference. Please see below example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;field_1&lt;/TD&gt;
&lt;TD&gt;field_2&lt;/TD&gt;
&lt;TD&gt;results&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;003,004,006&lt;/TD&gt;
&lt;TD&gt;003,004&lt;/TD&gt;
&lt;TD&gt;006&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;002,003,005&lt;/TD&gt;
&lt;TD&gt;002,005&lt;/TD&gt;
&lt;TD&gt;003&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;003,004&lt;/TD&gt;
&lt;TD&gt;003,004,006&lt;/TD&gt;
&lt;TD&gt;006&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;002,005&lt;/TD&gt;
&lt;TD&gt;002,003,005&lt;/TD&gt;
&lt;TD&gt;003&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And perhaps yet another example why having multiple values in a single field such as "003, 004, 006" is a poor idea in general.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 14:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Field-comparison/m-p/482479#M286867</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-30T14:24:30Z</dc:date>
    </item>
  </channel>
</rss>

