<?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: How do I replace words in a character string based on words in another data set? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296763#M62226</link>
    <description>&lt;P&gt;I suppose it could be more efficient if we load table 'A' into a Hash object, but no comparison is done. Here is an old school way of doing it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	input id words$;
	cards;
1  CAR
2  DOG
3  MAN
;

data b;
	infile cards truncover;
	input b_id sentences$100.;
	cards;
1  THE DOG RODE IN THE CAR WITH THE MAN
2  THIS CHEESEBURGER IS GREAT
;

data want;
	set b;

	do i=1 to nobs;
		set a nobs=nobs point=i;
		
		sentences=prxchange(cats('s/\b',words,'\b/HAT/'),-1,sentences);
	end;

	keep b_id sentences;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Sep 2016 15:12:59 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2016-09-06T15:12:59Z</dc:date>
    <item>
      <title>How do I replace words in a character string based on words in another data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296754#M62225</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem that I hope someone could help with.&amp;nbsp; I'm fairly new to SAS (9.4) so I apologize if my description is not clear and does not use the appropriate SAS terminology.&amp;nbsp; Here is the problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 SAS data sets - data set A contains over 500 words and&amp;nbsp;data set&amp;nbsp;B contains over 10,000 complex character strings.&amp;nbsp; I would like to write a program that will evaluate&amp;nbsp;every word data set B to see if it exists in data set A.&amp;nbsp; If it does, then replace the word with something else (the replacement is abritrary) and put the final result in data set C.&amp;nbsp; For example, if the replacement word is HAT, then:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Set A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; CAR&lt;/P&gt;&lt;P&gt;2&amp;nbsp; DOG&lt;/P&gt;&lt;P&gt;3&amp;nbsp; MAN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Set B&lt;/P&gt;&lt;P&gt;1&amp;nbsp; THE DOG RODE IN THE CAR WITH THE MAN&lt;/P&gt;&lt;P&gt;2&amp;nbsp; THIS CHEESEBURGER IS GREAT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Set C&lt;/P&gt;&lt;P&gt;1&amp;nbsp; THE HAT RODE IN THE HAT WITH THE HAT&lt;/P&gt;&lt;P&gt;2&amp;nbsp; THIS CHEESEBURGER IS GREAT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried finding a solution to this problem in this message board and others but have not found a satisfactory solution.&amp;nbsp; Any help will be greatly appreciated.&amp;nbsp; Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 14:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296754#M62225</guid>
      <dc:creator>DSW</dc:creator>
      <dc:date>2016-09-06T14:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I replace words in a character string based on words in another data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296763#M62226</link>
      <description>&lt;P&gt;I suppose it could be more efficient if we load table 'A' into a Hash object, but no comparison is done. Here is an old school way of doing it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	input id words$;
	cards;
1  CAR
2  DOG
3  MAN
;

data b;
	infile cards truncover;
	input b_id sentences$100.;
	cards;
1  THE DOG RODE IN THE CAR WITH THE MAN
2  THIS CHEESEBURGER IS GREAT
;

data want;
	set b;

	do i=1 to nobs;
		set a nobs=nobs point=i;
		
		sentences=prxchange(cats('s/\b',words,'\b/HAT/'),-1,sentences);
	end;

	keep b_id sentences;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Sep 2016 15:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296763#M62226</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-09-06T15:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I replace words in a character string based on words in another data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296781#M62234</link>
      <description>&lt;P&gt;Wow, this is great.&amp;nbsp; Thank you so much, it works beautifully.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 16:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-replace-words-in-a-character-string-based-on-words-in/m-p/296781#M62234</guid>
      <dc:creator>DSW</dc:creator>
      <dc:date>2016-09-06T16:53:16Z</dc:date>
    </item>
  </channel>
</rss>

