<?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 a string within &amp;quot; &amp;quot; in Sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772684#M245373</link>
    <description>&lt;P&gt;I would use either powershell or bash-script, depending on the os SAS is installed on. Or an editor like notepad++.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Oct 2021 11:30:01 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-10-07T11:30:01Z</dc:date>
    <item>
      <title>Replace a string within " " in Sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772678#M245370</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have multiple sas programs(around 1000). I have a requirement&amp;nbsp; that I have to replace a string with new string , the old string have contents inside " " which will keep changing.&amp;nbsp; for e.g&lt;/P&gt;
&lt;P&gt;in first program I have this string&lt;/P&gt;
&lt;P&gt;Old String =&amp;nbsp; Name&amp;nbsp; abc&amp;nbsp; "I have three books";&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;this I have to replace with new string&lt;/P&gt;
&lt;P&gt;New String = Name abc "I need coffee" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In second program I have this string&lt;/P&gt;
&lt;P&gt;Old String =&amp;nbsp; Name&amp;nbsp; sam&amp;nbsp; "I am going to office";&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;this I have to replace with new string&lt;/P&gt;
&lt;P&gt;New String = Name&amp;nbsp; sam "I will be dancing"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so on we have strings like this&amp;nbsp; in different programs.&lt;/P&gt;
&lt;P&gt;The basic idea is I have to swap String value after NAME to new string value. pattern will be same&lt;/P&gt;
&lt;P&gt;Old String have first value as NAME second is name of person and then after space inside " " value which needs to be replaced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly suggest any approach or macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 11:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772678#M245370</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-10-07T11:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string within " " in Sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772684#M245373</link>
      <description>&lt;P&gt;I would use either powershell or bash-script, depending on the os SAS is installed on. Or an editor like notepad++.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 11:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772684#M245373</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-07T11:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string within " " in Sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772686#M245375</link>
      <description>can you please help me script(bas-script) or any links where i can find something similar with issue ?</description>
      <pubDate>Thu, 07 Oct 2021 11:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772686#M245375</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-10-07T11:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string within " " in Sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772691#M245377</link>
      <description>&lt;P&gt;Sorry, but i haven't written any bash-script in the last 12 years, unfortunately i am bound to sas on windows &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 11:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772691#M245377</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-07T11:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string within " " in Sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772711#M245383</link>
      <description>&lt;P&gt;You appear to have two problems here.&amp;nbsp; First is how to find and replace the string.&lt;/P&gt;
&lt;P&gt;Sounds like you should be able to use a regular expression, but that depends a lot on how precisely you can describe the pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you talking about a full line of code from the file?&amp;nbsp; Or could these four "word" sequences appear in the middle of a longer line from the file?&amp;nbsp; Or perhaps only at the front or the end of the line?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second is you want to edit a bunch of TEXT files (programs are stored in text files).&lt;/P&gt;
&lt;P&gt;Do you want to edit all of the files in a particular folder?&lt;BR /&gt;Do you have a list of the files you want to edit?&lt;BR /&gt;Where do you want to place the NEW versions of the files?&lt;/P&gt;
&lt;P&gt;If you can solve the find and replace issue you might be able to modify all of the files in one data step by perhaps using wildcards in infile statement and the FILENAME= and FILEVAR= options on the infile and file statement. Or perhaps by using a list of file names to drive the generation of INFILE and FILE statements using the FILEVAR= option on both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772711#M245383</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-07T12:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string within " " in Sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772722#M245386</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;since SAS file are basic text files, I would perform the replacements directly from SAS and reserve powershell for more complex tasks.&lt;/P&gt;
&lt;P&gt;This is how you could achieve what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO replaceCodeLine();
      %*Define here your replacement strategy;
      %*codeLine is one line of code in the current SAS program beeing read;
      if index(codeLine,'I have three books')           then codeLine=tranwrd(codeLine,'I have three books','I need coffee');
      else if index(codeLine,'I am going to office')    then codeLine=tranwrd(codeLine,'I am going to office','I will be dancing');

      %*You could use regex as well depending on your replacement needs;
%MEND replaceCodeLine;

%MACRO proceedCurrentSasPgm(fullpath=);
   %*Performs replacement for the current SAS file;
   FILENAME saspgm "&amp;amp;fullpath.";

   DATA _CurrentSasPgmDS;
      *Read each line of code;
      infile saspgm dsd truncover;
      input codeLine $32767.;
   RUN;

   DATA _NULL_;
     SET _CurrentSasPgmDS;
     *Perform replacement;
     %replaceCodeLine();
     file saspgm;
     *write out to file;
     put codeLine;
   RUN;

   *Clean up;
   PROC DATASETS lib=work nolist; delete _CurrentSasPgmDS; RUN;QUIT;
   filename saspgm clear;
%MEND proceedCurrentSasPgm;

*Get list of *.sas files in directory and subdirectories;
%let filepath=C:\Temp\test\*.sas;
filename tmp pipe "dir /b /s /a:-D ""&amp;amp;filepath."" 2&amp;gt;&amp;amp;1";

DATA _NULL_;
  infile tmp dlm="¬";
  length Fullpath $2000;
  input Fullpath;
  *Loop through the list of SAS files and perform replacements in each one;
  call execute('%nrstr(%proceedCurrentSasPgm(fullpath='||strip(fullPath)||'));');
RUN;
filename tmp clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-within-quot-quot-in-Sas/m-p/772722#M245386</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-10-07T13:37:02Z</dc:date>
    </item>
  </channel>
</rss>

