<?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: Rename External File in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10708#M1075</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It sure helps. As far as I can see, you don't really have an index that Macro loop can use, so we will have to go from scratch:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*To get all the old files names that need to be renamed*/&lt;/P&gt;&lt;P&gt;filename ren pipe "dir c\test\*.sas /b /s";&lt;/P&gt;&lt;P&gt;/*To get the corresponding new file names*/&lt;/P&gt;&lt;P&gt;data ren;&lt;/P&gt;&lt;P&gt;infile ren;&lt;/P&gt;&lt;P&gt;input old : $250.;&lt;/P&gt;&lt;P&gt;new=tranwrd(old,'January','February');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;/*To rename them all*/&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set ren;&lt;/P&gt;&lt;P&gt;rc=rename(old, new, 'file');&lt;/P&gt;&lt;P&gt;put rc;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Feb 2012 20:24:39 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-02-22T20:24:39Z</dc:date>
    <item>
      <title>Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10703#M1070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to batch rename files in a windows directory using SAS?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Directory : C:\Test\&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Files: January_Test1.sas | January_Test2.sas | January_Test3.sas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I need to rename the month name for each file manually every month...wondering if there is some way to run a sas command that goes to that directory...renames anything January to February. Updating these values once monthly in a sas command mght make this easier than doing it manually..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please provide sample code if possible, Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 19:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10703#M1070</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2012-02-22T19:03:47Z</dc:date>
    </item>
    <item>
      <title>Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10704#M1071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can run system commands with at least three SAS statements, e.g., x&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will be easier to provide a code example if you provide a list of the filenames you have and how you want each renamed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 19:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10704#M1071</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-22T19:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10705#M1072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this out, not tested, so subjected to being tweaked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro rename (old=, new=);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;%do i=1 %to 3;&lt;/P&gt;&lt;P&gt;rc=rename("c:\test\&amp;amp;old._test&amp;amp;i..sas", "c:\test\&amp;amp;new._test&amp;amp;i..sas", 'file');&lt;/P&gt;&lt;P&gt;put rc;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%rename (old=january,new=february)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check if 'rc=0' to make sure rename was successful. &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 19:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10705#M1072</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-02-22T19:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10706#M1073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Files in my folder (&lt;SPAN style="background-color: #eef4f9;"&gt;C:\Test\&lt;/SPAN&gt;) are :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;January_2012_Report_1.sas&lt;/P&gt;&lt;P&gt;January_2012_System_2.sas&lt;/P&gt;&lt;P&gt;January_2012_Core_4.sas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the January to be renamed to February only....rest of the file name should stay the same. Basically these month names will need to be updated each month.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 19:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10706#M1073</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2012-02-22T19:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10707#M1074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry...does not seem to work. I have added my actual file names as a reply to Art... not sure if this helps?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 19:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10707#M1074</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2012-02-22T19:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10708#M1075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It sure helps. As far as I can see, you don't really have an index that Macro loop can use, so we will have to go from scratch:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*To get all the old files names that need to be renamed*/&lt;/P&gt;&lt;P&gt;filename ren pipe "dir c\test\*.sas /b /s";&lt;/P&gt;&lt;P&gt;/*To get the corresponding new file names*/&lt;/P&gt;&lt;P&gt;data ren;&lt;/P&gt;&lt;P&gt;infile ren;&lt;/P&gt;&lt;P&gt;input old : $250.;&lt;/P&gt;&lt;P&gt;new=tranwrd(old,'January','February');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;/*To rename them all*/&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set ren;&lt;/P&gt;&lt;P&gt;rc=rename(old, new, 'file');&lt;/P&gt;&lt;P&gt;put rc;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 20:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10708#M1075</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-02-22T20:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10709#M1076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was able to change the names by using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options noxwait;&lt;/P&gt;&lt;P&gt;x 'cd c:\art';&lt;/P&gt;&lt;P&gt;x 'ren January*.sas February*.sas';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first x statement was to change to the directory where the files were located.&amp;nbsp; The second one changed any SAS program, in that directory, that started with the string 'January' and changed it to 'February'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 20:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10709#M1076</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-22T20:39:07Z</dc:date>
    </item>
    <item>
      <title>Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10710#M1077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is awesome... one more question. If my file path has an "&amp;amp;" in a folder name this does not seem to work. Any way to fix that? You can suppose my file new file path is :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C:\Test\Test&amp;amp;Exp\Totals &amp;amp; Reps\&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 20:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10710#M1077</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2012-02-22T20:59:23Z</dc:date>
    </item>
    <item>
      <title>Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10711#M1078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you were replying to Haikuo's post, I presume that is the method you are asking about.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You just have to mask the name.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename ren pipe "dir %nrstr(&lt;SPAN style="background-color: #eef4f9;"&gt;C:\Test\Test&amp;amp;Exp\Totals &amp;amp; Reps\&lt;/SPAN&gt;*.sas /b /s)";&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 21:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10711#M1078</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-22T21:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10712#M1079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Art. On top of Art's suggestion, there is a native approach that DOS has to deal with this kind of problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename ren pipe 'dir "C:\Test\Test&amp;amp;Exp\Totals &amp;amp; Reps\*.sas" /b /s';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note, the single quote and the double quote need to be the exact way it is. BTW, it didn't work not because you have '&amp;amp;', blank was supposed to be the culprit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the rest of the code, as it has been tweaked a bit to accomodate the new requirement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ren;&lt;/P&gt;&lt;P&gt;infile ren pad;&lt;/P&gt;&lt;P&gt;input old $250.;&lt;/P&gt;&lt;P&gt;new=tranwrd(old,'January','February');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*To rename them all*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set ren;&lt;/P&gt;&lt;P&gt;rc=rename(old, new, 'file');&lt;/P&gt;&lt;P&gt;put rc;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 22:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10712#M1079</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-02-22T22:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10713#M1080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I prefer to use .bat file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;filename x pipe 'dir "C:\Test\Test&amp;amp;Exp\Totals &amp;amp; Reps\January*.sas " /b';
data _null_;
 infile x;
 file 'c:\rename.bat';
 input x : $40.;
 y=catx(' ','rename',x,tranwrd(x,'January','February'));
 put y;
run;
x 'cd "C:\Test\Test&amp;amp;Exp\Totals &amp;amp; Reps\"';
x 'c:\rename.bat';


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Feb 2012 03:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10713#M1080</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-02-23T03:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Rename External File</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10714#M1081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you art and Haikuo, both your solutions worked very well!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Feb 2012 14:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-External-File/m-p/10714#M1081</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2012-02-23T14:06:07Z</dc:date>
    </item>
  </channel>
</rss>

