<?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: Copying and renaming a file in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/333575#M62839</link>
    <description>&lt;P&gt;Hi, I know this is an old post, there are a few other possibilities for copying an external file to a seperate location. I'm not sure what the prompt is for the copy, as I don't run into that issue, and perhaps it's because I have a different version (9.4) but I noticed that the original X Copy wasn't correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In an X Copy, the X and copy are outside the quotes, and the file you want to copy and where/what the new name will be need to be in their own seperate quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X COPY "&amp;amp;PATH_DM.\Trial_logs.sas7bdat" "&amp;amp;PATH_DM.\Trail_logs_&amp;amp;TODATE..sas7bdat";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another option (&lt;STRONG&gt;Which I personally like much better&lt;/STRONG&gt;) is the &lt;STRONG&gt;systask command&lt;/STRONG&gt; option. This means of copying has many more controls than RC or a typical X Copy. You have the option to Taskname, waitfor, status, ect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYSTASK COMMAND "COPY &amp;amp;PATH_DM.\Trail_logs.sas7bdat &amp;amp;PATH_DM.\&lt;SPAN&gt;Trail_logs_&amp;amp;TODATE..sas7bdat&lt;/SPAN&gt;" WAIT MNAME=GDDINCOPY TASKNAME=GDDINCOPY STATUS=TASK; WAITFOR GDDINCOPY;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are other options, though IMO I think these 2 do it all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy Coding.&lt;/P&gt;&lt;P&gt;Monster&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2017 21:03:07 GMT</pubDate>
    <dc:creator>XMonsterX</dc:creator>
    <dc:date>2017-02-16T21:03:07Z</dc:date>
    <item>
      <title>Copying and renaming a file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17715#M3396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having great difficulty achieving something that I'm sure shouldn't be a problem. All I want to do is get SAS to copy a file (not a SAS dataset) to a new name in the same directory. The new name contains the current year/month yyyy-mm and&amp;nbsp; this is stored in a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried "x call copy" but dos keeps stopping to prompt me to tell it if it's a file or directory I'm copying, which is no good at 1am when the program will run. I read you can pass parameter /i to turn this off, but it doesn't seem to work.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried x calling a batch file and passing the year/month as a parameter, but I can't get this to work either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does any know how I achieve this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 10:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17715#M3396</guid>
      <dc:creator>JamesNewcombe</dc:creator>
      <dc:date>2011-12-20T10:29:17Z</dc:date>
    </item>
    <item>
      <title>Copying and renaming a file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17716#M3397</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;I believe what you're missing is "option noxwait;'&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#exittemp.htm"&gt;http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#exittemp.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below code works for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options noxwait;&lt;BR /&gt;%let date=20111220;&lt;BR /&gt;data _null_;&lt;BR /&gt;/*&amp;nbsp; x "copy c:\temp\testdata.txt c:\temp\testdata_&amp;amp;date..txt";*/&lt;BR /&gt;&amp;nbsp; rc= system("copy c:\temp\testdata.txt c:\temp\testdata_&amp;amp;date..txt");&lt;BR /&gt;&amp;nbsp; put rc=;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using "system" instead of 'x' allows you to store a return code (zero if successful) and do some extra stuff based on the return code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Patrick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 10:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17716#M3397</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-12-20T10:56:19Z</dc:date>
    </item>
    <item>
      <title>Copying and renaming a file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17717#M3398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks Patrick, I knew there had to be an easy answer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 11:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17717#M3398</guid>
      <dc:creator>JamesNewcombe</dc:creator>
      <dc:date>2011-12-20T11:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming a file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17718#M3399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I still have one problem. The directory path to the file I want to copy has spaces in it. Normally in DOS you'd just put quotes around the path, but the string in the system command is already in quotes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way around this, apart from renaming the path?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 11:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17718#M3399</guid>
      <dc:creator>JamesNewcombe</dc:creator>
      <dc:date>2011-12-20T11:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming a file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17719#M3400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the QUOTE function.&amp;nbsp; This will put quotes around the string and also double any existing quotes so that they get based through to the OS properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; oldname = 'This file has spaces.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; newname = 'This_file_doesnot.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rc= system(quote(catx(' ','copy',quote(trim(oldname)),quote(trim(newname)))));&lt;/P&gt;&lt;P&gt;&amp;nbsp; put rc=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or if you want to do with macro statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;%let oldname = "This file has spaces.txt";&lt;/P&gt;&lt;P&gt;%let newmame = This_file_doesnot.txt ;&lt;/P&gt;&lt;P&gt;%sysexec(%sysfunc(quote(copy &amp;amp;oldname &amp;amp;newname)));&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 14:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/17719#M3400</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-20T14:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming a file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/333575#M62839</link>
      <description>&lt;P&gt;Hi, I know this is an old post, there are a few other possibilities for copying an external file to a seperate location. I'm not sure what the prompt is for the copy, as I don't run into that issue, and perhaps it's because I have a different version (9.4) but I noticed that the original X Copy wasn't correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In an X Copy, the X and copy are outside the quotes, and the file you want to copy and where/what the new name will be need to be in their own seperate quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X COPY "&amp;amp;PATH_DM.\Trial_logs.sas7bdat" "&amp;amp;PATH_DM.\Trail_logs_&amp;amp;TODATE..sas7bdat";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another option (&lt;STRONG&gt;Which I personally like much better&lt;/STRONG&gt;) is the &lt;STRONG&gt;systask command&lt;/STRONG&gt; option. This means of copying has many more controls than RC or a typical X Copy. You have the option to Taskname, waitfor, status, ect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYSTASK COMMAND "COPY &amp;amp;PATH_DM.\Trail_logs.sas7bdat &amp;amp;PATH_DM.\&lt;SPAN&gt;Trail_logs_&amp;amp;TODATE..sas7bdat&lt;/SPAN&gt;" WAIT MNAME=GDDINCOPY TASKNAME=GDDINCOPY STATUS=TASK; WAITFOR GDDINCOPY;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are other options, though IMO I think these 2 do it all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy Coding.&lt;/P&gt;&lt;P&gt;Monster&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 21:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Copying-and-renaming-a-file/m-p/333575#M62839</guid>
      <dc:creator>XMonsterX</dc:creator>
      <dc:date>2017-02-16T21:03:07Z</dc:date>
    </item>
  </channel>
</rss>

