<?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 to replace the word  using array and tranwrd in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614325#M179550</link>
    <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304875"&gt;@D_ph14&lt;/a&gt; , but it can get what I want</description>
    <pubDate>Sun, 29 Dec 2019 22:47:13 GMT</pubDate>
    <dc:creator>blueskyxyz</dc:creator>
    <dc:date>2019-12-29T22:47:13Z</dc:date>
    <item>
      <title>How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614031#M179424</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	length string $1000;
    string= "THIS IS A REALLY LONG STRING THAT I WANT TO SPLIT G LONG ENOUGH TO SPLIT";
	array str{4} $ 50 ('not', 'is', 'a', 'to' ) ;
	mid=string;
	do i=1 to 4;
		y=trim(upcase(str{i}));
		x=trim(str{i});
		if index(mid,y) then do; mid=tranwrd(mid,y ,x );
			put x y mid;
		end;
	end;
	string=mid;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;my code cannot work, to get the final result as below:&lt;/P&gt;&lt;P&gt;THIS is a REALLY LONG STRING THAT I WANT to SPLIT G LONG ENOUGH to SPLIT&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 08:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614031#M179424</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2019-12-27T08:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614033#M179425</link>
      <description>&lt;P&gt;replace a word a time, this can work, for example, tranwrd(string,"IS" ,"is" );&lt;/P&gt;&lt;P&gt;but it cannot work using array and do-loop, why? how to modify the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 08:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614033#M179425</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2019-12-27T08:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614037#M179427</link>
      <description>&lt;P&gt;Try using &lt;EM&gt;trim&lt;/EM&gt; for variables x and y:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if index(mid,trim(y)) then do;&lt;BR /&gt;&amp;nbsp; mid=tranwrd(mid, trim(y), trim(x) );&lt;BR /&gt;&amp;nbsp; put x y mid;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 08:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614037#M179427</guid>
      <dc:creator>D_ph14</dc:creator>
      <dc:date>2019-12-27T08:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614053#M179439</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	length string want $1000;
    string= "THIS IS A REALLY LONG STRING THAT I WANT TO SPLIT G LONG ENOUGH TO SPLIT";
	array str{4} $ 50 ('not', 'is', 'a', 'to' ) ;
	call missing(want);
	do i=1 to countw(string,' ');
      temp=scan(string,i,' ');
	  if lowcase(temp) in str then want=catx(' ',want,lowcase(temp));
	   else want=catx(' ',want,temp);
	end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 11:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614053#M179439</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-27T11:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614059#M179441</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298115"&gt;@blueskyxyz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can easily do that using the PRXCHANGE function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	length string $1000;
	string="THIS IS A REALLY LONG STRING THAT I WANT TO SPLIT G LONG ENOUGH TO SPLIT";
	mid=prxchange('s/(\bNOT\b|\bIS\b|\bA\b|\bTO\b)/\L$1/', -1, string);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code :&lt;/P&gt;
&lt;P&gt;1 - Search for the pattern NOT or IS or A or TO (\b identifies a word boundary)&lt;/P&gt;
&lt;P&gt;2 - Replace it ($1) by its lowercase equivalent (lowcase &amp;nbsp;= \L) as many times as needed (-1 as a second argument)&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 12:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614059#M179441</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-27T12:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614231#M179489</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298115"&gt;@blueskyxyz&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Possible. But you need to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;make sure that only the words in the list are lowcased if surrounded by blanks&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;account for the endpoints with one-sided blanks if any&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep = s) ;                                                                                                                  
  s = "IS IT POSSIBLE TO LOWCASE WORDS A IS NOT TO IN A LONG STRING USING TRANWRD OR NOT" ;                                             
  array w $3 w1-w4 ("a" "is" "not" "to") ;                                                                                              
  retain b "" ;                                                                                                                         
  do over w ;                                                                                                                           
    s = left (tranwrd (b || s || b, b || upcase (trim (w)) || b, b || trim (w) || b)) ;                                                 
  end ;                                                                                                                                 
  put s ;                                                                                                                              
run ;     
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;is IT POSSIBLE to LOWCASE WORDS a is not to IN a LONG STRING USING TRANWRD OR not
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2019 21:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614231#M179489</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-12-28T21:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614242#M179492</link>
      <description>&lt;P&gt;Same as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;just with a small change to the RegEx&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                                                                                                  
  s = "IS IT POSSIBLE TO LOWCASE WORDS A IS NOT TO IN A LONG STRING USING TRANWRD OR NOT" ;  
  s=prxchange('s/\b(a|is|not|to)\b/\L\1/oi',-1,trim(s));                                                                                                      
  put s ;  
  stop; 
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Dec 2019 02:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614242#M179492</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-29T02:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614254#M179502</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;, thanks for your method using RegEx.&lt;BR /&gt;&lt;BR /&gt;It is very clear with your detailed explanations.</description>
      <pubDate>Sun, 29 Dec 2019 06:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614254#M179502</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2019-12-29T06:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614324#M179549</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt; , my confusion is clear up.</description>
      <pubDate>Sun, 29 Dec 2019 22:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614324#M179549</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2019-12-29T22:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614325#M179550</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304875"&gt;@D_ph14&lt;/a&gt; , but it can get what I want</description>
      <pubDate>Sun, 29 Dec 2019 22:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614325#M179550</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2019-12-29T22:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614327#M179551</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; ，I appreciate your help, if the variable has a lot of characters, it will time consuming to combine each word a time using catx function.</description>
      <pubDate>Sun, 29 Dec 2019 23:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614327#M179551</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2019-12-29T23:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the word  using array and tranwrd</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614366#M179570</link>
      <description>Did you try Patrick's PRXCHANGE() ?</description>
      <pubDate>Mon, 30 Dec 2019 11:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-word-using-array-and-tranwrd/m-p/614366#M179570</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-30T11:12:36Z</dc:date>
    </item>
  </channel>
</rss>

