BookmarkSubscribeRSS Feed
whymath
Barite | Level 11

I am using fcopy() function to copy an Excel file, here is the code:

filename spec "spec.xlsx" recfmt=n;
filename speccopy "%sysfunc(pathname(work))\spec.xlsx" recfmt=n;

data _null_;
  rc=fcopy('spec','speccopy');
  if rc>0 then do;
    msg=sysmsg();
    put msg=;
  end;
run;

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?

8 REPLIES 8
Tom
Super User Tom
Super User

Talk to Microsoft about changing the behavior of Windows?

Quentin
Super User

Looks like fcopy() is happy to copy an Excel file while the file is open.  Also copies fine if the file is open and there are unsaved changes to the file.  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.

 

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.

whymath
Barite | Level 11
Maybe your OS is Linux? SAS behaves oppsite on my Windows Server OS.
Quentin
Super User
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.
whymath
Barite | Level 11

Tried PC SAS, still doesn't work. This is the screeshot:

whymath_0-1766131095120.png

What's your enviroment?

SASKiwi
PROC Star

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. 

whymath
Barite | Level 11

Thank you guys.

Finnally, I use x command to replace fcopy function.

x copy "spec.xlsx" "%sysfunc(pathname(work))";

Still waitting for SAS solution.

LinusH
Tourmaline | Level 20
Placing office files in SharePoint and in Teams let you edit the file simultaneously, perhaps this also works for SAS access?
Haven't tried since my SAS server can't access those due to firewall rules.
Data never sleeps

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 178 views
  • 0 likes
  • 5 in conversation