<?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 strings and delte if in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484721#M287073</link>
    <description>&lt;P&gt;That is a good first step, but for this type of problem you normally have to worry about tokens that are wholly contained in other tokens.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if one or more of the two listst include both Car and Cartoon?&amp;nbsp; How would you adjust your solution to handle that situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Aug 2018 12:53:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-08-07T12:53:15Z</dc:date>
    <item>
      <title>Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484622#M287068</link>
      <description>&lt;P&gt;I need to compare two strings from two macro variables, best in proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;StringA = Cars Dog Cat&lt;/P&gt;&lt;P&gt;StringB = Cars House Model Fish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If like in the example Dog and Cat didnt hit in StringB it has to be removed, so that&lt;/P&gt;&lt;P&gt;StringA = Cars or %let NewString = Cars&lt;/P&gt;&lt;P&gt;If nothing hits than %put something.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way or a function?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 06:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484622#M287068</guid>
      <dc:creator>TT_T</dc:creator>
      <dc:date>2018-08-07T06:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484642#M287069</link>
      <description>&lt;P&gt;This might work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let StringA = Cars Dog Cat;
%let StringB = Cars House Model Fish;

%macro findWords;
	%let remove=&amp;amp;stringA;
	%do i=1 %to %sysfunc(countw(&amp;amp;stringA));
		%let word=%scan(&amp;amp;stringB,&amp;amp;i);
		%let remove=%sysfunc(tranwrd(&amp;amp;remove, &amp;amp;word,));
	%end;
	%let StringA=%sysfunc(tranwrd(&amp;amp;StringA, &amp;amp;remove,));
	%put remove=&amp;amp;remove;
	%put stringA=&amp;amp;StringA;
	%put stringB=&amp;amp;stringB;
%mend;
%findWords;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 08:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484642#M287069</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2018-08-07T08:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484655#M287070</link>
      <description>&lt;P&gt;Thxs for the replie.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It can be that StringA = House Dog Cat Cars;&lt;/P&gt;&lt;P&gt;For that it doesnt work, but thxs for your idea. I will try on with your solution.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 08:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484655#M287070</guid>
      <dc:creator>TT_T</dc:creator>
      <dc:date>2018-08-07T08:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484677#M287071</link>
      <description>&lt;P&gt;Why does it not work with&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;House Dog Cat Cars&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let StringA = House Dog Cat Cars;
%let StringB = Cars House Model Fish;

%macro findWords;
	%let remove=&amp;amp;stringA;
	%do i=1 %to %sysfunc(countw(&amp;amp;stringA));
		%let word=%scan(&amp;amp;stringB,&amp;amp;i);
		%let remove=%sysfunc(tranwrd(&amp;amp;remove, &amp;amp;word,));
	%end;
	%let StringA=%sysfunc(tranwrd(&amp;amp;StringA, &amp;amp;remove,));
	%put remove=&amp;amp;remove;
	%put stringA=&amp;amp;StringA;
	%put stringB=&amp;amp;stringB;
%mend;
%findWords;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;returns&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;remove=Dog Cat
stringA=House   Cars
stringB=Cars House Model Fish&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 10:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484677#M287071</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2018-08-07T10:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484721#M287073</link>
      <description>&lt;P&gt;That is a good first step, but for this type of problem you normally have to worry about tokens that are wholly contained in other tokens.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if one or more of the two listst include both Car and Cartoon?&amp;nbsp; How would you adjust your solution to handle that situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 12:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484721#M287073</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T12:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484723#M287074</link>
      <description>&lt;P&gt;Loop over the words in one of the list. Check if the word is in the other list. If so add it to the resulting string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let StringA = Cars Dog Cat;
%let StringB = Cars House Model Fish;
%let Expect = Cars ;

%macro both(a,b);
  %local i return word;
  %do i=1 %to %sysfunc(countw(&amp;amp;a,%str( )));
    %let word=%scan(&amp;amp;a,&amp;amp;i,%str( ));
    %if %sysfunc(findw(&amp;amp;b,&amp;amp;word,,s)) %then %let return=&amp;amp;return &amp;amp;word ;
  %end;
&amp;amp;return.
%mend both;

%put %both(&amp;amp;stringa,&amp;amp;stringb);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 13:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484723#M287074</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T13:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484730#M287075</link>
      <description>&lt;P&gt;Because of the issue that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;mentioned, this can become complex and involve %SYSFUNC and FINDW.&amp;nbsp; Instead, I prefer to pad each string with blanks and use %INDEX:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let StringA = Cars Dog Cat;
%let StringB = Cars House Model Fish;
%let NewString = ;

%macro findwords;
   %local k nextword;
   %do k=1 %to %sysfunc(countw(&amp;amp;StringA));
      %let nextword = %scan(&amp;amp;StringA, &amp;amp;k);
      %if  %index(%str( &amp;amp;StringB ), %str( &amp;amp;nextword ))
      %then %let NewString = &amp;amp;NewString &amp;amp;nextword;
   %end;
%mend findwords;
%findwords
%put Matches found:  &amp;amp;NewString;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's untested code so might need a minor tweak.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 13:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/484730#M287075</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-07T13:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two strings and delte if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/485043#M287076</link>
      <description>&lt;P&gt;Thxs for the replies. It´s a bit tricky because there are ongoing action´s, i will try to implement some of your answer´s. Thxs&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 08:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-strings-and-delte-if/m-p/485043#M287076</guid>
      <dc:creator>TT_T</dc:creator>
      <dc:date>2018-08-08T08:27:20Z</dc:date>
    </item>
  </channel>
</rss>

