<?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 find string in column from another table and replace. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25418#M4437</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello, (I started in sas)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two tables :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data first;&lt;/P&gt;&lt;P&gt;infile cards dlm=','; &lt;/P&gt;&lt;P&gt;input city$ :30. any$ :20. ;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;oakland is very beautifull,azerty&lt;/P&gt;&lt;P&gt;I never go to oakland,qwerty&lt;/P&gt;&lt;P&gt;abc fremont fgh ,anything&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and a secondary :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data transco;&lt;/P&gt;&lt;P&gt;infile cards dlm=','; &lt;/P&gt;&lt;P&gt;input field1$ :30. field2$ :20. ;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;oakland,berkeley&lt;/P&gt;&lt;P&gt;fremont,newark&lt;/P&gt;&lt;P&gt;stanford,loyola&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I would like find any data from field1 in my secondary table in first table for city, and if string match, I would like to replace him from field2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ex : oakland is very beautifull &amp;gt;&amp;gt; transform in : berkeley is very beautifull&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I never go to oakland &amp;gt;&amp;gt; I never go to berkeley&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abc fremont fgh &amp;gt;&amp;gt; abc loyola fgh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Jul 2011 07:21:05 GMT</pubDate>
    <dc:creator>buju</dc:creator>
    <dc:date>2011-07-04T07:21:05Z</dc:date>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25418#M4437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello, (I started in sas)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two tables :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data first;&lt;/P&gt;&lt;P&gt;infile cards dlm=','; &lt;/P&gt;&lt;P&gt;input city$ :30. any$ :20. ;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;oakland is very beautifull,azerty&lt;/P&gt;&lt;P&gt;I never go to oakland,qwerty&lt;/P&gt;&lt;P&gt;abc fremont fgh ,anything&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and a secondary :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data transco;&lt;/P&gt;&lt;P&gt;infile cards dlm=','; &lt;/P&gt;&lt;P&gt;input field1$ :30. field2$ :20. ;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;oakland,berkeley&lt;/P&gt;&lt;P&gt;fremont,newark&lt;/P&gt;&lt;P&gt;stanford,loyola&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I would like find any data from field1 in my secondary table in first table for city, and if string match, I would like to replace him from field2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ex : oakland is very beautifull &amp;gt;&amp;gt; transform in : berkeley is very beautifull&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I never go to oakland &amp;gt;&amp;gt; I never go to berkeley&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abc fremont fgh &amp;gt;&amp;gt; abc loyola fgh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jul 2011 07:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25418#M4437</guid>
      <dc:creator>buju</dc:creator>
      <dc:date>2011-07-04T07:21:05Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25419#M4438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; let's help.&lt;/P&gt;&lt;P&gt;your example contains an error : abc fremont fgh &amp;gt;&amp;gt; abc newark fgh. &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here's the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data first;&lt;BR /&gt;infile cards dlm=','; &lt;BR /&gt;input city$ :30. any$ :20. ;&lt;BR /&gt;CARDS;&lt;BR /&gt;oakland is very beautifull,azerty&lt;BR /&gt;I never go to oakland,qwerty&lt;BR /&gt;abc fremont fgh ,anything&lt;BR /&gt;testing empty match,mojojo&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data transco;&lt;BR /&gt;infile cards dlm=','; &lt;BR /&gt;input field1$ :30. field2$ :20. ;&lt;BR /&gt;CARDS;&lt;BR /&gt;oakland,berkeley&lt;BR /&gt;fremont,newark&lt;BR /&gt;stanford,loyola&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* let's get the input char (orig) and the changer char (dest) */&lt;BR /&gt;proc sql;&lt;BR /&gt;select field1,field2 into:orig1-:orig99,:dest1-:dest99 from transco;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put number of observations in transco : &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* now search the string in the dataset and tell if it's found */&lt;BR /&gt;data first2 (drop=i);&lt;BR /&gt;set first;&lt;BR /&gt;format orig $30. dest $20. i 10. found 1.;&lt;BR /&gt;found=0;&lt;BR /&gt;do i=1 to &amp;amp;sqlobs;&lt;BR /&gt;orig=symget(compress("orig"!!i));&lt;BR /&gt;dest=symget(compress("dest"!!i));/*&lt;BR /&gt;test=compress("orig"!!i);*/&lt;BR /&gt;if index(city,trim(orig)) then do; found=1; output;end;&lt;BR /&gt;end;&lt;BR /&gt;if found=0 then do;orig='';dest='';output;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* now replace the string */&lt;BR /&gt;data first3;&lt;BR /&gt;set first2;&lt;BR /&gt;if found then do;&lt;BR /&gt; city2=tranwrd(city,trim(orig),trim(dest));&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt; city2=city;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do the search and replace in two different datasteps but you can do it in one step. &lt;/P&gt;&lt;P&gt;Take care if you do this to gat out the do loop or you could replace twice a city.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;enjoy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jul 2011 09:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25419#M4438</guid>
      <dc:creator>mojerry2</dc:creator>
      <dc:date>2011-07-04T09:15:46Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25420#M4439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;abc fremont fgh &amp;gt;&amp;gt; abc loyola fgh should be abc fremont fgh &amp;gt;&amp;gt; abc newark fgh ?&lt;/P&gt;&lt;P&gt;I have to leave now.will be here tomorrow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data first;
infile cards dlm=',';
input city$ :30. any$ :20. ;
CARDS;
oakland is very beautifull,azerty
I never go to oakland,qwerty
abc fremont fgh ,anything
;
run;

data transco;
infile cards dlm=',';
input field1$ :30. field2$ :20. ;
CARDS;
oakland,berkeley
fremont,newark
stanford,loyola
;
run;
data want;
 set first;
 do i=1 to _nobs;
&amp;nbsp; set transco nobs=_nobs point=i;
&amp;nbsp; if findw(city,strip(field1)) then city=tranwrd(city,strip(field1),strip(field2));
 end;
drop field:;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jul 2011 09:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25420#M4439</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-07-04T09:19:28Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25421#M4440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you very much : it's work very well. it's help me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jul 2011 10:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25421#M4440</guid>
      <dc:creator>buju</dc:creator>
      <dc:date>2011-07-04T10:26:49Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25422#M4441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you its work : after I'm replace function findw by findc(because I use sas 9.1 not 9.2), but it's godd example, and it's very easy to use. thank a lot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jul 2011 10:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25422#M4441</guid>
      <dc:creator>buju</dc:creator>
      <dc:date>2011-07-04T10:29:44Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25423#M4442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;then use indexw() or index() find() to search that word.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2011 02:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25423#M4442</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-07-05T02:58:20Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25424#M4443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; watch out the example of ksharp doesn't quit when the city was found.&lt;/P&gt;&lt;P&gt;so if you have in your example to change oakland to berkeley but a few records after you have to change berkeley to new ark in your transco table then it could give some problems.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2011 05:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25424#M4443</guid>
      <dc:creator>mojerry2</dc:creator>
      <dc:date>2011-07-05T05:42:55Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25425#M4444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi. I understand what you mean ,It is about tree problem and as you think there is also be a dead loop problem, such as &lt;/P&gt;&lt;P&gt;berkeley -&amp;gt; oakland&lt;/P&gt;&lt;P&gt;oakland -&amp;gt;&amp;nbsp; berkeley.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If as your logic that could be :&lt;/P&gt;&lt;P&gt;berkeley -&amp;gt; oakland&lt;/P&gt;&lt;P&gt;oakland -&amp;gt; washington&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why not directly write as :&lt;/P&gt;&lt;P&gt;berkeley -&amp;gt; washington&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it is hard to judge something without seeing op's orgin data .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2011 07:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25425#M4444</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-07-05T07:36:51Z</dc:date>
    </item>
    <item>
      <title>find string in column from another table and replace.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25426#M4445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; true &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2011 07:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-string-in-column-from-another-table-and-replace/m-p/25426#M4445</guid>
      <dc:creator>mojerry2</dc:creator>
      <dc:date>2011-07-05T07:48:20Z</dc:date>
    </item>
  </channel>
</rss>

