<?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 Using SAS to alter all occurences of a string in a SQL script in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422034#M103770</link>
    <description>&lt;P&gt;So we're upgrading our databases, and there are a lot of legacy scripts that are, for the most part, entirely salvageable, but they will all need to be updated in the near future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I'm looking for a way for SAS to read a .sql script, and change any entries of, say VEGETABLE.BANANA to FRUIT.BANANA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I could change it in notepad or MySQL manually, but I'm looking to see if SAS has a way to do it, as it's a functionality that I feel could be useful in reducing workload down the road.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2017 16:21:32 GMT</pubDate>
    <dc:creator>ruhickson</dc:creator>
    <dc:date>2017-12-18T16:21:32Z</dc:date>
    <item>
      <title>Using SAS to alter all occurences of a string in a SQL script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422034#M103770</link>
      <description>&lt;P&gt;So we're upgrading our databases, and there are a lot of legacy scripts that are, for the most part, entirely salvageable, but they will all need to be updated in the near future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I'm looking for a way for SAS to read a .sql script, and change any entries of, say VEGETABLE.BANANA to FRUIT.BANANA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I could change it in notepad or MySQL manually, but I'm looking to see if SAS has a way to do it, as it's a functionality that I feel could be useful in reducing workload down the road.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 16:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422034#M103770</guid>
      <dc:creator>ruhickson</dc:creator>
      <dc:date>2017-12-18T16:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to alter all occurences of a string in a SQL script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422040#M103771</link>
      <description>&lt;P&gt;I wouldn't use SAS, use PowerShell or a scripting language. They're much faster with this type of work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: If you really do want to do this using SAS though, you can search on here for examples, this question has been asked and answered.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/100435"&gt;@ruhickson&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;So we're upgrading our databases, and there are a lot of legacy scripts that are, for the most part, entirely salvageable, but they will all need to be updated in the near future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Essentially, I'm looking for a way for SAS to read a .sql script, and change any entries of, say VEGETABLE.BANANA to FRUIT.BANANA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I could change it in notepad or MySQL manually, but I'm looking to see if SAS has a way to do it, as it's a functionality that I feel could be useful in reducing workload down the road.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 16:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422040#M103771</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-18T16:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to alter all occurences of a string in a SQL script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422098#M103788</link>
      <description>&lt;P&gt;I have done this for a few smallish scripts BUT there are things to look out for. First is does "VEGETABLE." ever occur as part of another compound such as "LEGUMEVEGETABLE."? if so then order of replacement becomes an issue.&lt;/P&gt;
&lt;P&gt;Second is case ever important? "Vegetable" is not "VEGETABLE" is not "vEGetaBLE". If source case doesn't need to be retained but may want to replace "vegetable" and "VEGETABLE" then the Upcase may be of interest. But if you have other text, such as Label statements or attributes, you may not want to upcase those.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most important is &lt;STRONG&gt;never ever replace code in place &lt;/STRONG&gt;unless you have made good copies elsewhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very brief example is:&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; infile "your script file" lrecl=1000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; file "outputscriptfile"&amp;nbsp; lrecl=1000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tranwrd(_infile_,'VEGETABLE.','FRUIT.');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; put _infile_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Lrecl should be the length of the longest line expected. If your code doesn't run more that 256 on any line then should be okay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Multiple changes could be made with multiple tranwrd statements but order may matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 19:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422098#M103788</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-18T19:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS to alter all occurences of a string in a SQL script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422195#M103811</link>
      <description>&lt;P&gt;Slightly arranged.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   infile "your script file" lrecl=1000;
   file   "outputscriptfile" lrecl=1000;
   input;
   do while(index(_infile_,' VEGETABLE.'));
     _infile_=tranwrd(_infile_,' VEGETABLE.',' FRUIT.');
   end;
   put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 04:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-to-alter-all-occurences-of-a-string-in-a-SQL-script/m-p/422195#M103811</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-12-19T04:10:07Z</dc:date>
    </item>
  </channel>
</rss>

