<?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: Tranwrd function : Conditional Execution: Exact word replacement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-function-Conditional-Execution-Exact-word-replacement/m-p/553171#M153797</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;maybe like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length cond2 $ 256; /* assure enough space for a variable*/
  cond2 = cond;
  cond2 = tranwrd(cond, "=" , " = "); /* assure extra space between variable name and "=" */
  do a = 1 to countw(listvar) ; 
    var=compress(scan(listvar,a,' '));
    cond2=tranwrd(cond2
                 ,strip(var)!!" " /* serach for "WORD " instead "WORD"  */
                 ,cats(domain,'.',strip(var))!!" ");
  end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2019 11:06:29 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2019-04-23T11:06:29Z</dc:date>
    <item>
      <title>Tranwrd function : Conditional Execution: Exact word replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-function-Conditional-Execution-Exact-word-replacement/m-p/553166#M153795</link>
      <description>&lt;P&gt;I am trying to append dataset name (DSN) for each variable present in the logical condition, the variable names are present in another column LISTVAR and logical condition in COND&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;domain="ABC";&lt;BR /&gt;listvar="ABCAT ABTESTCD ABTEST ABTXT";&lt;BR /&gt;cond="ABCAT = 'ADMINISTRATION' AND ABTESTCD = 'ASSIST' AND ABTEST = 'ASSISTANCE' AND ABTXT = 'EVENT'";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;do a= 1 to countw(listvar) ; &lt;BR /&gt;var=compress(scan(listvar,a,' '));&lt;BR /&gt;cond=tranwrd(cond,strip(var),cats(domain,'.',strip(var)));&lt;BR /&gt;end ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;Required output:DSN.ABCAT = 'ADMINISTRATION' AND DSN.ABTESTCD = 'ASSIST' AND DSN.ABTEST = 'ASSISTANCE' AND DSN.ABTXT = 'EVENT'&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Current output: DSN.ABCAT = 'ADMINISTRATION' AND &lt;U&gt;&lt;STRONG&gt;DSN.DSN.ABTESTCD&lt;/STRONG&gt;&lt;/U&gt; = 'ASSIST' AND DSN.ABTEST = 'ASSISTANCE' AND DSN.ABTXT = 'EVENT'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here the problem is both ABTESTCD and ABTEST are present in the variable list , initially ABTESTCD is appended with domain name i.e DSN.ABTESTCD , when it goes for ABTEST&lt;BR /&gt;the ABTESTCD is again appending with DSN so it is becoming DSN.DSN.ABTESTCD, here the dataset is getting appended twice because of ABTEST. &lt;BR /&gt;How to avoid such similar strings to get replaced by TRANWRD and the TRANWRD is also not functional conditionally also. Like i have tested by considering the length of the variable,but still replaces it . Is their any way to avoid this and replace only the exact word/string and this has to be dynamic since there will be many such scenarios.Can such scenarios be handled using PRXCHANGE?&lt;/P&gt;
&lt;P&gt;Tried with arrays for each word creation, but i think its little lengthy.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 10:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-function-Conditional-Execution-Exact-word-replacement/m-p/553166#M153795</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-04-23T10:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Tranwrd function : Conditional Execution: Exact word replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-function-Conditional-Execution-Exact-word-replacement/m-p/553171#M153797</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;maybe like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length cond2 $ 256; /* assure enough space for a variable*/
  cond2 = cond;
  cond2 = tranwrd(cond, "=" , " = "); /* assure extra space between variable name and "=" */
  do a = 1 to countw(listvar) ; 
    var=compress(scan(listvar,a,' '));
    cond2=tranwrd(cond2
                 ,strip(var)!!" " /* serach for "WORD " instead "WORD"  */
                 ,cats(domain,'.',strip(var))!!" ");
  end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 11:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-function-Conditional-Execution-Exact-word-replacement/m-p/553171#M153797</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-04-23T11:06:29Z</dc:date>
    </item>
  </channel>
</rss>

