<?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: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423060#M104016</link>
    <description>&lt;P&gt;Perhaps you could provide the full question you want to ask.&amp;nbsp; You have several posts asking more or less exactly the same thing, for example:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Extract-a-portion-of-a-string-variable-from-column-name/m-p/422293#M103834" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Extract-a-portion-of-a-string-variable-from-column-name/m-p/422293#M103834&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have yet to tell me what is wrong with the code I provided you which loops over each word delimited - in this way you could check word{i-2}+word{i-1}+word{i} = your given string, however I am not going to further waste my time trying to guess what you want.&amp;nbsp; Provide a clear question, with test data in the form of datastep (i.e. so we don't have to type it all in and guess what structure), and a clear example of what you want out.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2017 11:39:07 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-12-21T11:39:07Z</dc:date>
    <item>
      <title>Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423024#M104004</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to replace the string &lt;STRONG&gt;"he_is_nice"&lt;/STRONG&gt; with &lt;STRONG&gt;"cool"&lt;/STRONG&gt; whenever it appears on a column. I can easily do it using tranwrd function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The catch is, I only want to replace it if it's the starting of a word, not when it's in the middle. For example let's say if I have following&amp;nbsp;var column, the result would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;var&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;result_var&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;she_is_nice&lt;/TD&gt;&lt;TD&gt;she_is_nice&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;oh_he_is_nice&lt;/TD&gt;&lt;TD&gt;oh_cool&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;he_is_cool&lt;/TD&gt;&lt;TD&gt;he_is_cool&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;well_he_is_nice_to_be_with&lt;/TD&gt;&lt;TD&gt;well_cool_to_be_with&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ohhe_is_nice&lt;/TD&gt;&lt;TD&gt;ohhe_is_nice&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I don't want to replace when it's&amp;nbsp;starting from the middle of a word (my delimiter is '_'). Is it easy to do with tranwrd? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 10:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423024#M104004</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2017-12-21T10:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423035#M104008</link>
      <description>&lt;P&gt;How about:&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;if var =: 'he_is_nice' then
  result_var = tranwrd(var, 'he_is_nice', 'cool');
else
  result_var = var;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 10:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423035#M104008</guid>
      <dc:creator>lethcons</dc:creator>
      <dc:date>2017-12-21T10:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423052#M104013</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134349"&gt;@lethcons&lt;/a&gt;&amp;nbsp;doesn't work. ':'&amp;nbsp; is there to tell it it's the beginning of the phrase? That's not the case though. Also the delimiter is different.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423052#M104013</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2017-12-21T11:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423054#M104014</link>
      <description>&lt;P&gt;One way..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var:$50.;
datalines;
she_is_nice
oh_he_is_nice
he_is_cool
well_he_is_nice_to_be_with
ohhe_is_nice
;

data want;
	set have;
	resultvar=var;
	if substr(var, find(var, "he_is_nice")-1, 1) in ("_", "") 
		then resultvar=tranwrd(var, "he_is_nice", "cool");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423054#M104014</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-21T11:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423060#M104016</link>
      <description>&lt;P&gt;Perhaps you could provide the full question you want to ask.&amp;nbsp; You have several posts asking more or less exactly the same thing, for example:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Extract-a-portion-of-a-string-variable-from-column-name/m-p/422293#M103834" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Extract-a-portion-of-a-string-variable-from-column-name/m-p/422293#M103834&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have yet to tell me what is wrong with the code I provided you which loops over each word delimited - in this way you could check word{i-2}+word{i-1}+word{i} = your given string, however I am not going to further waste my time trying to guess what you want.&amp;nbsp; Provide a clear question, with test data in the form of datastep (i.e. so we don't have to type it all in and guess what structure), and a clear example of what you want out.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423060#M104016</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-21T11:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423061#M104017</link>
      <description>&lt;P&gt;Perfect, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423061#M104017</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2017-12-21T11:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423062#M104018</link>
      <description>&lt;P&gt;Anytime, glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423062#M104018</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-21T11:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423068#M104019</link>
      <description>&lt;P&gt;Sorry&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;, I am new to sas (having mostly used 'R' previously) and trying to learn things through example as I find documentations a bit difficult to understand in some cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And your code was perfectly fine, it did work. This question was a simpler one, but since I'm dealing with lot of strings, I'm trying to learn about &lt;STRONG&gt;trim, substr, scan, compress, find, tranwrd,&amp;nbsp;prxchange,&amp;nbsp;prxparse,&amp;nbsp;prxnext&lt;/STRONG&gt; etc etc. as much as possible through examples. And I'll provide t&lt;SPAN&gt;est data in the form of datastep for future questions. Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423068#M104019</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2017-12-21T11:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use tranwrd to replace string - ONLY FROM STARTING OF A WORD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423082#M104024</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var:$50.;
datalines;
he_is_nice
she_is_nice
oh_he_is_nice
he_is_cool
well_he_is_nice_to_be_with
ohhe_is_nice
he_is_nice_xx
;

data want;
	set have;
	resultvar=prxchange("s/\bhe_is_nice\b/cool/",-1,var);
	resultvar=prxchange("s/_he_is_nice_/_cool_/",-1,resultvar);
	resultvar=prxchange("s/_he_is_nice\b/_cool/",-1,resultvar);
	resultvar=prxchange("s/\bhe_is_nice_/cool_/",-1,resultvar);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 13:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-tranwrd-to-replace-string-ONLY-FROM-STARTING-OF-A-WORD/m-p/423082#M104024</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-21T13:04:14Z</dc:date>
    </item>
  </channel>
</rss>

