<?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: fcopy function failed when the file is opened. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981020#M379019</link>
    <description>&lt;P&gt;Talk to Microsoft about changing the behavior of Windows?&lt;/P&gt;</description>
    <pubDate>Thu, 18 Dec 2025 14:14:48 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-12-18T14:14:48Z</dc:date>
    <item>
      <title>fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/980943#M379015</link>
      <description>&lt;P&gt;I am using fcopy() function to copy an Excel file, here is the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename spec "spec.xlsx" recfmt=n;
filename speccopy "%sysfunc(pathname(work))\spec.xlsx" recfmt=n;

data _null_;
  rc=fcopy('spec','speccopy');
  if rc&amp;gt;0 then do;
    msg=sysmsg();
    put msg=;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It works usually, but failed while I am editing this Excel file, how to make fcopy() just make a copy of the Excel file while the file is on editing?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 06:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/980943#M379015</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2025-12-18T06:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981020#M379019</link>
      <description>&lt;P&gt;Talk to Microsoft about changing the behavior of Windows?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 14:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981020#M379019</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-18T14:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981021#M379020</link>
      <description>&lt;P&gt;Looks like fcopy() is happy to copy an Excel file while the file is open.&amp;nbsp; Also copies fine if the file is open and there are unsaved changes to the file.&amp;nbsp; But it would make sense that when you hit SAVE in Excel, at some point in that process when it writes the file to disk, Excel is going to get an exclusive lock on the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your timing is occasionally unlucky enough that you are trying to copy the file while someone is writing to the file, I think the best you can do is detect the problem and try again.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 14:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981021#M379020</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-12-18T14:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981040#M379021</link>
      <description>&lt;P&gt;This is a feature of Windows and Excel. Any attempt to read an Excel file in SAS under Windows will fail if it is already opened in Excel. FCOPY, PROC IMPORT, the EXCEL or XLSX LIBNAME engines will all fail.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 19:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981040#M379021</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2025-12-18T19:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981059#M379023</link>
      <description>&lt;P&gt;Thank you guys.&lt;/P&gt;
&lt;P&gt;Finnally, I use x command to replace fcopy function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x copy "spec.xlsx" "%sysfunc(pathname(work))";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Still waitting for SAS solution.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2025 01:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981059#M379023</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2025-12-19T01:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981060#M379024</link>
      <description>Maybe your OS is Linux? SAS behaves oppsite on my Windows Server OS.</description>
      <pubDate>Fri, 19 Dec 2025 01:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981060#M379024</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2025-12-19T01:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981061#M379025</link>
      <description>I tested on local Windows with PC SAS. With the Excel file open, I could copy it using Windows file explorer and could copy it using copy(). But could be different for Windows server.</description>
      <pubDate>Fri, 19 Dec 2025 01:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981061#M379025</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-12-19T01:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981075#M379027</link>
      <description>&lt;P&gt;Tried PC SAS, still doesn't work. This is the screeshot:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="whymath_0-1766131095120.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112362i272BEA2AF54CBFEC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="whymath_0-1766131095120.png" alt="whymath_0-1766131095120.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What's your enviroment?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2025 07:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981075#M379027</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2025-12-19T07:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981082#M379028</link>
      <description>Placing office files in SharePoint and in Teams let you edit the file simultaneously, perhaps this also works for SAS access?&lt;BR /&gt;Haven't tried since my SAS server can't access those due to firewall rules.</description>
      <pubDate>Fri, 19 Dec 2025 09:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981082#M379028</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-12-19T09:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981156#M379045</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;My understanding is that SAS should hold an exclusive copy for fcopy to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Dec 2025 03:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981156#M379045</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2025-12-22T03:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: fcopy function failed when the file is opened.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981162#M379046</link>
      <description>&lt;P&gt;SAS uses locking to prevent that a file is changed while FCOPY is in progress (keep in mind that FCOPY can be used with file references pointing to remote locations, so the copy could take quite some time and the result be inconsistent). Since Excel keeps an open handle on a file, FCOPY fails because the lock fails.&lt;/P&gt;
&lt;P&gt;Your method of using an external command is the proper workaround. For documentation in the SAS log, you should use PIPE to run the external command:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "copy 'spec.xlsx' '%sysfunc(pathname(work))' 2&amp;gt;&amp;amp;1";

data _null_;
infile oscmd;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Dec 2025 10:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fcopy-function-failed-when-the-file-is-opened/m-p/981162#M379046</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-12-22T10:03:32Z</dc:date>
    </item>
  </channel>
</rss>

