<?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: Compare two coloums in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913154#M359925</link>
    <description>&lt;P&gt;You understood perfectly! Do loop is the best for me. I learned a lot from this code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One more question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;How can I check the cases where there are no spaces in the string?&lt;/P&gt;&lt;P&gt;For example : Greatdaytest&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jan 2024 18:22:19 GMT</pubDate>
    <dc:creator>Neptun83</dc:creator>
    <dc:date>2024-01-26T18:22:19Z</dc:date>
    <item>
      <title>Compare two coloums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913122#M359913</link>
      <description>Hello!&lt;BR /&gt;I have two tables with two columns.&lt;BR /&gt;If the character string of table1 column contains the word in table2 coloum,then I want to delete it from the character string of table1 column.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;Table 1 column: Table two column:&lt;BR /&gt;Next day. Day&lt;BR /&gt;Best day. Great&lt;BR /&gt;Great day test.&lt;BR /&gt;&lt;BR /&gt;The result I would like:&lt;BR /&gt;Next&lt;BR /&gt;Best&lt;BR /&gt;Test&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;What is the best method to do this?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jan 2024 14:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913122#M359913</guid>
      <dc:creator>Neptun83</dc:creator>
      <dc:date>2024-01-26T14:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two coloums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913123#M359914</link>
      <description>I use SAS EG 8.2</description>
      <pubDate>Fri, 26 Jan 2024 14:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913123#M359914</guid>
      <dc:creator>Neptun83</dc:creator>
      <dc:date>2024-01-26T14:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two coloums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913124#M359915</link>
      <description>&lt;P&gt;Not sure what you mean. Your presentation of the data is not clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean you have two datasets that each have two variables? Or does each dataset have only one variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have two separate datasets then how do you want to match the observations?&amp;nbsp; Do you want to paste them side by side so the first observations from dataset ONE is paired with the first observation from dataset TWO?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the case of the letters in the strings matter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the substrings have to be complete words in the full strings?&amp;nbsp; If so what characters can be used to indicate word boundaries?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's assume case is to be ignored and only spaces demark word boundaries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's create some sample datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data strings;
  input string $50.;
cards;
Next day
Best day
Great day test
;

data words;
  input word $20. ;
cards;
Day
Great
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the list of words is actually so short then just hard code them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set strings;
  length new_string $50;
  do i=1 to countw(string,' ');
      word=scan(string,i,' ');
      if upcase(word) not in ('GREAT','DAY') then new_string=catx(' ',new_string,word);
  end;
  drop i word;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                          new_
Obs    string            string

 1     Next day           Next
 2     Best day           Best
 3     Great day test     test
&lt;/PRE&gt;
&lt;P&gt;If the list of words is short enough to fit into a single character variable (32k bytes) then you might want to use a regular expression instead.&amp;nbsp; Perhaps something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set strings;
  length new_string $50 ;
  new_string=compbl(prxchange("s/\b(great|day)\b/ /i",-1,string));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could use a simple macro variable to build the part of the regular expression that changes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select word into :wordlist separated by '|' 
    from words
  ;
quit;
data want;
  set strings;
  length new_string $50 ;
  new_string=compbl(prxchange("s/\b(&amp;amp;wordlist)\b/ /i",-1,string));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you have a lot of substrings to remove you will need to go back to the DO loop method.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps by putting the list of words into an array?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set strings;
  if _n_=1 then do i=1 to nobs;
     set words nobs=nobs;
     array words[5000] $20 _temporary_ ;
     words[i]=upcase(word);
  end;
  length new_string $50 ;
  do i=1 to countw(string,' ');
    word=scan(string,i,' ');
    if not (upcase(word) in words) then new_string=catx(' ',new_string,word);
  end;
  drop i word;
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>Fri, 26 Jan 2024 15:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913124#M359915</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-26T15:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two coloums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913130#M359919</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/461511"&gt;@Neptun83&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I use SAS EG 8.2&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note:&amp;nbsp; The version of the tool you use to create and submit SAS code is not that important for a programming question.&amp;nbsp; What is more important is the &lt;STRONG&gt;version of SAS&lt;/STRONG&gt; that you are using Enterprise Guide to connect to.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But your question is basic enough that the answer should work on any currently used version of SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 15:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913130#M359919</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-26T15:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two coloums</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913154#M359925</link>
      <description>&lt;P&gt;You understood perfectly! Do loop is the best for me. I learned a lot from this code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One more question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;How can I check the cases where there are no spaces in the string?&lt;/P&gt;&lt;P&gt;For example : Greatdaytest&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 18:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-coloums/m-p/913154#M359925</guid>
      <dc:creator>Neptun83</dc:creator>
      <dc:date>2024-01-26T18:22:19Z</dc:date>
    </item>
  </channel>
</rss>

