<?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: Replace string with another string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465695#M118793</link>
    <description>&lt;P&gt;You already have your answer, both answers from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;should work. I am here just to comment that your original example code will not work for your purpose. The reason being SAS using FIXED length variable, you will need byte abundancy or some walk-around (rename etc.) to replace&amp;nbsp;with a longer&amp;nbsp;chars, notice &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s example with some blanks padded. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 May 2018 13:28:12 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2018-05-29T13:28:12Z</dc:date>
    <item>
      <title>Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465626#M118779</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a sentence&amp;nbsp;like "I am a student in a college in a city in India&amp;nbsp;to study masters"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the above sentence, I want to replace the second&amp;nbsp;occurrence of "in" with "from".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest me code to replace&amp;nbsp;it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have tried with the following code, i made it. But am looking for another way which makes easy to execute.&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;data x;

word = "I am a student in a college in a city in India to study masters";

substr(word, 29, 2) = "from";

run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you &amp;amp; regards.&lt;/P&gt;&lt;P&gt;Manoj&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 08:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465626#M118779</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-05-29T08:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465629#M118780</link>
      <description>&lt;P&gt;You probably want to use the TRANWRD function:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Word=tranwrd(Word,'to','from');&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 08:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465629#M118780</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-05-29T08:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465635#M118782</link>
      <description>&lt;P&gt;Thank you for replay,&lt;/P&gt;&lt;P&gt;&amp;nbsp;by using TRANWRD all in 's will be replaced by "from", but i want to replace only second "in" with "from"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 09:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465635#M118782</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-05-29T09:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465640#M118783</link>
      <description>&lt;P&gt;And what is the logic to assume that?&amp;nbsp; Simply put, if you had the string:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token string"&gt;I am a student in a college in a city in India to study masters&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;How are we to note that the second in is to be replaced, and not the others?&lt;/P&gt;
&lt;P&gt;I mean I could tell you to substr or scan the string, but that would only help in this one specific case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 10:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465640#M118783</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-29T10:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465642#M118784</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NEWWORD=prxchange('s/(.*? in .*?)( in )(.*)/$1 from $3/',-1,WORD);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I hope there's no error, I can't test atm.&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 10:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465642#M118784</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-29T10:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465679#M118792</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
word = "I am a student in a college in a city in India to study masters    ";
put word= ;

pid=prxparse('/\bin\b/i');
s=1;e=length(word);
call prxnext(pid,s,e,word,p,l);
n=0;
do while(p&amp;gt;0);
 n+1;
 if n=2 then do;want=substr(word,1,p-1)||'from'||substr(word,p+l);leave;end;
 call prxnext(pid,s,e,word,p,l);
end;
put want= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 May 2018 13:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465679#M118792</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-29T13:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465695#M118793</link>
      <description>&lt;P&gt;You already have your answer, both answers from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;should work. I am here just to comment that your original example code will not work for your purpose. The reason being SAS using FIXED length variable, you will need byte abundancy or some walk-around (rename etc.) to replace&amp;nbsp;with a longer&amp;nbsp;chars, notice &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s example with some blanks padded. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 13:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465695#M118793</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2018-05-29T13:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465721#M118796</link>
      <description>&lt;P&gt;DATA TEMP;&lt;BR /&gt;word = "I am a student in a college in a city in INDIA to study masters";&lt;/P&gt;&lt;P&gt;word_len= LENGTH(STRIP(word));&lt;BR /&gt;fst_pos= FINDW(STRIP(word),'in');&lt;BR /&gt;snd_pos= FINDW(STRIP(word),'in',fst_pos+1);&lt;/P&gt;&lt;P&gt;new_str_part1= substr(STRIP(word),1,snd_pos-1);&lt;BR /&gt;new_str_part2= 'from';&lt;BR /&gt;new_str_part3= substr(STRIP(word),snd_pos+2);&lt;/P&gt;&lt;P&gt;new_word= CAT(new_str_part1,new_str_part2,new_str_part3);&lt;/P&gt;&lt;P&gt;DROP word_len fst_pos snd_pos new_str_part:;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC PRINT DATA=TEMP;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 14:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465721#M118796</guid>
      <dc:creator>mahesh146</dc:creator>
      <dc:date>2018-05-29T14:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465919#M118855</link>
      <description>Thank you, this one worked</description>
      <pubDate>Wed, 30 May 2018 07:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465919#M118855</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-05-30T07:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465920#M118856</link>
      <description>Thank you this one worked</description>
      <pubDate>Wed, 30 May 2018 07:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/465920#M118856</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-05-30T07:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/466022#M118884</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Can you explain the red one stand for what ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;prxchange('s/(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.*?&lt;/FONT&gt;&lt;/STRONG&gt; in &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.*?&lt;/FONT&gt;&lt;/STRONG&gt;)( in )(.*)/&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 14:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/466022#M118884</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-30T14:01:07Z</dc:date>
    </item>
  </channel>
</rss>

