Hi everyone,
I’m trying to copy an Excel file (.xls) from one folder to another on the same drive using SAS, but I’m running into an issue.
Here’s the code I’m using:
filename in1 "H:\folder1\file1.xls";
filename ou1 "H:\folder2\file1.xls";
data _null_;
rc = fcopy("in1", "ou1");
if rc = 0 then put 'Copy successful';
else put 'Copy failed';
run;What’s happening:
Has anyone encountered this issue before or knows what might be causing fcopy to fail like this? Are there any additional checks or alternative approaches I should consider? Any troubleshooting ideas?
Thanks in advance!
What version of SAS are you using? I know that FCOPY has improved in later versions to handle more cases.
But for an immediate solution of your problem, try an alternative approach to perform a binary copy of the file.
https://blogs.sas.com/content/sasdummy/2013/09/17/copy-file-macro/
XLS files are BINARY files. So make sure to tell SAS that.
You can try RECFM=N as suggested by @ChrisHemedinger 's blog post.
filename in1 "H:\folder1\file1.xls" recfm=N;
filename ou1 "H:\folder2\file1.xls" recfm=N;
Or use RECFM=F and LRECL=512.
You also could try this code:
%let in1=H:\folder1\file1.xls;
%let ou1=H:\folder2\file1.xls;
data _null_;
rc=rename("&in1","&ou1",'file');
run;
filename in1 "H:\folder1\file1.xls" lrecl=1 recfm=N;
filename ou1 "H:\folder2\file1.xls" lrecl=1 recfm=N;
data _null_;
rc = fcopy("in1", "ou1");
if rc = 0 then put 'Copy successful';
else put 'Copy failed';
run;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.
Ready to level-up your skills? Choose your own adventure.