<?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: Replacing words in a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480604#M286618</link>
    <description>&lt;P&gt;a=index(question, '[');&lt;/P&gt;&lt;P&gt;newvar=substr(question,1,a-1)||put(name,$50.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;??&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jul 2018 19:21:03 GMT</pubDate>
    <dc:creator>pau13rown</dc:creator>
    <dc:date>2018-07-23T19:21:03Z</dc:date>
    <item>
      <title>Replacing words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480593#M286616</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-23 at 20.00.24.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21943iAE69F86DDA06F2DD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-23 at 20.00.24.png" alt="Screen Shot 2018-07-23 at 20.00.24.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Code used to create above data set is:&lt;/P&gt;&lt;P&gt;data Questions;&lt;BR /&gt;length Question $100 Name $20;&lt;BR /&gt;infile datalines dlm=',';&lt;BR /&gt;input Question $ Name $ ;&lt;BR /&gt;cards;&lt;BR /&gt;When was your last interaction with Pablo Matinee,Pablo Matinee&lt;BR /&gt;When was your last interaction with Lucien Koku,Lucien Koku&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to replace every&amp;nbsp;occurrence of the customer Name in the Question with [Name]. So what i intend to achieve is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-23 at 20.03.00.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21944iCF043CE9F1FAFFD4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-23 at 20.03.00.png" alt="Screen Shot 2018-07-23 at 20.03.00.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i have written so far is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data New;&lt;BR /&gt;set Questions;&lt;BR /&gt;tranwrd(Question,Name,"%str(%[)Name%str(%])");&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but this has not worked.&amp;nbsp; Please can anyone suggest a solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 19:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480593#M286616</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-23T19:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480599#M286617</link>
      <description>&lt;P&gt;You may want to try the TRANSTRN() function, for it lets you remove part of string and not leave a blank behind:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; new_var = transtrn(Question, Name, "[Name]");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 19:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480599#M286617</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2018-07-23T19:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480604#M286618</link>
      <description>&lt;P&gt;a=index(question, '[');&lt;/P&gt;&lt;P&gt;newvar=substr(question,1,a-1)||put(name,$50.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;??&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 19:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480604#M286618</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-07-23T19:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480605#M286619</link>
      <description>&lt;P&gt;Use macros in last resort. They are not needed here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data New;
set Questions;
length newQuestion $100;
newQuestion  = tranwrd(Question, trim(name), "[Name]");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 19:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480605#M286619</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-07-23T19:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480607#M286620</link>
      <description>&lt;P&gt;TRANWRD is for a word but you have two words so it's not going to match. Is it possible to have multiple iterations of a persons name in the text? And is it guaranteed that the name is always at the end?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do want a TRANSLATE/TRANS family of functions for sure though. If you have multiple occurrences it could be problematic though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134464"&gt;@frupaul&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-23 at 20.00.24.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21943iAE69F86DDA06F2DD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-23 at 20.00.24.png" alt="Screen Shot 2018-07-23 at 20.00.24.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Code used to create above data set is:&lt;/P&gt;
&lt;P&gt;data Questions;&lt;BR /&gt;length Question $100 Name $20;&lt;BR /&gt;infile datalines dlm=',';&lt;BR /&gt;input Question $ Name $ ;&lt;BR /&gt;cards;&lt;BR /&gt;When was your last interaction with Pablo Matinee,Pablo Matinee&lt;BR /&gt;When was your last interaction with Lucien Koku,Lucien Koku&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to replace every&amp;nbsp;occurrence of the customer Name in the Question with [Name]. So what i intend to achieve is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-23 at 20.03.00.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21944iCF043CE9F1FAFFD4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-23 at 20.03.00.png" alt="Screen Shot 2018-07-23 at 20.03.00.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i have written so far is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data New;&lt;BR /&gt;set Questions;&lt;BR /&gt;tranwrd(Question,Name,"%str(%[)Name%str(%])");&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but this has not worked.&amp;nbsp; Please can anyone suggest a solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 19:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-words-in-a-variable/m-p/480607#M286620</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-23T19:24:21Z</dc:date>
    </item>
  </channel>
</rss>

