<?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 Identifying the String and replacing in Quotes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/535850#M147186</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have a dataset with variable HAVE and another variable Replace consisting of some text to be replaced from HAVE to new value present in the same variable, &lt;BR /&gt;Old represent the value present in the HAVE variable and New is the value to be replaced in the same variabe HAVE. This has to be done dynamically by selecting the text from replace variable without manual checking.&lt;BR /&gt;I am trying to find the text in Old using FIND,SCAN,SUBSTRs function and then replacing the value with TRANWRD fucntion. Is there any direct approach/function/short cut to do this in much simpler way. The output variable is WANT for reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="1037"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="408"&gt;Have&lt;/TD&gt;
&lt;TD width="170"&gt;Replace&lt;/TD&gt;
&lt;TD width="459"&gt;Want&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Benchmark indices registered recovery from the day's &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;low&lt;/FONT&gt;&lt;/STRONG&gt; point.&lt;/TD&gt;
&lt;TD&gt;(old="low", new="high")&lt;/TD&gt;
&lt;TD&gt;Benchmark indices registered strong recovery from the day's &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;high&lt;/FONT&gt;&lt;/STRONG&gt; point.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Completes inspection &lt;STRONG&gt;&lt;FONT color="#993300"&gt;at&lt;/FONT&gt;&lt;/STRONG&gt; Factory&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;(old="at", new="in")&lt;/TD&gt;
&lt;TD&gt;Completes inspection &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;in&lt;/FONT&gt;&lt;/STRONG&gt; Factory&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Patient&lt;STRONG&gt;&lt;FONT color="#993300"&gt;;&lt;/FONT&gt;&lt;/STRONG&gt; status&lt;FONT color="#993300"&gt;;&lt;/FONT&gt; cardiac arrest&lt;/TD&gt;
&lt;TD&gt;(old=";",new=',')&lt;/TD&gt;
&lt;TD&gt;Patient&lt;STRONG&gt;&lt;FONT color="#003366"&gt;,&lt;/FONT&gt;&lt;/STRONG&gt; status&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;,&lt;/FONT&gt;&lt;/STRONG&gt; cardiac arrest&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Fri, 15 Feb 2019 13:25:16 GMT</pubDate>
    <dc:creator>keen_sas</dc:creator>
    <dc:date>2019-02-15T13:25:16Z</dc:date>
    <item>
      <title>Identifying the String and replacing in Quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/535850#M147186</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have a dataset with variable HAVE and another variable Replace consisting of some text to be replaced from HAVE to new value present in the same variable, &lt;BR /&gt;Old represent the value present in the HAVE variable and New is the value to be replaced in the same variabe HAVE. This has to be done dynamically by selecting the text from replace variable without manual checking.&lt;BR /&gt;I am trying to find the text in Old using FIND,SCAN,SUBSTRs function and then replacing the value with TRANWRD fucntion. Is there any direct approach/function/short cut to do this in much simpler way. The output variable is WANT for reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="1037"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="408"&gt;Have&lt;/TD&gt;
&lt;TD width="170"&gt;Replace&lt;/TD&gt;
&lt;TD width="459"&gt;Want&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Benchmark indices registered recovery from the day's &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;low&lt;/FONT&gt;&lt;/STRONG&gt; point.&lt;/TD&gt;
&lt;TD&gt;(old="low", new="high")&lt;/TD&gt;
&lt;TD&gt;Benchmark indices registered strong recovery from the day's &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;high&lt;/FONT&gt;&lt;/STRONG&gt; point.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Completes inspection &lt;STRONG&gt;&lt;FONT color="#993300"&gt;at&lt;/FONT&gt;&lt;/STRONG&gt; Factory&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;(old="at", new="in")&lt;/TD&gt;
&lt;TD&gt;Completes inspection &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;in&lt;/FONT&gt;&lt;/STRONG&gt; Factory&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Patient&lt;STRONG&gt;&lt;FONT color="#993300"&gt;;&lt;/FONT&gt;&lt;/STRONG&gt; status&lt;FONT color="#993300"&gt;;&lt;/FONT&gt; cardiac arrest&lt;/TD&gt;
&lt;TD&gt;(old=";",new=',')&lt;/TD&gt;
&lt;TD&gt;Patient&lt;STRONG&gt;&lt;FONT color="#003366"&gt;,&lt;/FONT&gt;&lt;/STRONG&gt; status&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;,&lt;/FONT&gt;&lt;/STRONG&gt; cardiac arrest&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Fri, 15 Feb 2019 13:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/535850#M147186</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-02-15T13:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the String and replacing in Quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/535864#M147194</link>
      <description>&lt;P&gt;First I would suggest fixing the replace column, it will just make your code longer if you have it all in one.&amp;nbsp; Have two columns:&lt;/P&gt;
&lt;P&gt;FIND&amp;nbsp; &amp;nbsp; &amp;nbsp;REPLACE&lt;/P&gt;
&lt;P&gt;low&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; high&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will make things easier.&lt;/P&gt;
&lt;P&gt;Second, should it replace all occurrences, what about casing?&amp;nbsp; What about low in a word, e.g. below?&lt;/P&gt;
&lt;P&gt;Tranwrd is probably the simplest method, e.g:&lt;/P&gt;
&lt;PRE&gt;want=tranwrd(have," low "," high ");
&lt;/PRE&gt;
&lt;P&gt;I put spaces in so as to get only th word, not be"low" for instance.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 14:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/535864#M147194</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-15T14:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the String and replacing in Quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/536472#M147432</link>
      <description>&lt;P&gt;The points raised by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;will need to be addressed, but as the question is presented the following might help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* set up data */
data have;
   infile datalines truncover;
   input have    $char70.;
   input replace $char30.;

   datalines4;
Benchmark indices registered recovery from the day's low point.
(old="low", new="high")
Completes inspection at Factory
(old="at", new="in")
Patient; status; cardiac arrest
(old=";",new=',')
That"s ok
(old='"',new="'")
This 'dataline' uses quotes
(old="'",new='"')
;;;;

data want;
   set have;

   length find_str repl_str $ 8;

   /* get 'old' string and remove quotes */
   find_str = strip(tranwrd(scanq(replace,1,','),'(old=',''));
   find_str = dequote(find_str);

   /* get 'new' string and remove quotes */
   repl_str = strip(tranwrd(scanq(replace,2,','),'new=',''));
   repl_str = substr(repl_str,1,length(repl_str) - 1);
   repl_str = dequote(repl_str);

   /* perform replace */
   want = tranwrd(have,strip(find_str),strip(repl_str));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Feb 2019 13:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-String-and-replacing-in-Quotes/m-p/536472#M147432</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-02-18T13:33:59Z</dc:date>
    </item>
  </channel>
</rss>

