Copy Excel Workbook and Save Under New Name

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Copy Excel Workbook and Save Under New Name

I am trying to use SAS to copy an existing excel workbook (a template) and save it with a new name in a different folder (once updated with current data).  I have tried both steps below, but I cannot get either to work.  It seems like it should be simple to do, the only difference between the 2 workbooks would be the file name and location.

 

First tried:

options noxwait;

data _null_;

rc= system("copy S:\sas\Regular Reports\Vacancy Template.xlsx S:\oim\Regular Reports\Vacancy Report &sysdate..xlsx");

 

put rc=;

run;

 

Then I tried:

options noxwait;

data _null_;

oldname="S:\sas\Regular Reports\Vacancy Template.xlsx";

newname="S:\oim\Regular Reports\Vacancy Report &sysdate..xlsx";

rc= system(quote(catx(' ','copy',quote(trim(oldname)),quote(trim(newname)))));

put rc=;

run;


Accepted Solutions
Solution
‎02-14-2018 01:12 PM
Super User
Posts: 23,663

Re: Copy Excel Workbook and Save Under New Name

Posted in reply to eferencik

If you're using SAS 9.4 try FCOPY instead.

 


eferencik wrote:

I am trying to use SAS to copy an existing excel workbook (a template) and save it with a new name in a different folder (once updated with current data).  I have tried both steps below, but I cannot get either to work.  It seems like it should be simple to do, the only difference between the 2 workbooks would be the file name and location.

 

First tried:

options noxwait;

data _null_;

rc= system("copy S:\sas\Regular Reports\Vacancy Template.xlsx S:\oim\Regular Reports\Vacancy Report &sysdate..xlsx");

 

put rc=;

run;

 

Then I tried:

options noxwait;

data _null_;

oldname="S:\sas\Regular Reports\Vacancy Template.xlsx";

newname="S:\oim\Regular Reports\Vacancy Report &sysdate..xlsx";

rc= system(quote(catx(' ','copy',quote(trim(oldname)),quote(trim(newname)))));

put rc=;

run;


 

View solution in original post


All Replies
Solution
‎02-14-2018 01:12 PM
Super User
Posts: 23,663

Re: Copy Excel Workbook and Save Under New Name

Posted in reply to eferencik

If you're using SAS 9.4 try FCOPY instead.

 


eferencik wrote:

I am trying to use SAS to copy an existing excel workbook (a template) and save it with a new name in a different folder (once updated with current data).  I have tried both steps below, but I cannot get either to work.  It seems like it should be simple to do, the only difference between the 2 workbooks would be the file name and location.

 

First tried:

options noxwait;

data _null_;

rc= system("copy S:\sas\Regular Reports\Vacancy Template.xlsx S:\oim\Regular Reports\Vacancy Report &sysdate..xlsx");

 

put rc=;

run;

 

Then I tried:

options noxwait;

data _null_;

oldname="S:\sas\Regular Reports\Vacancy Template.xlsx";

newname="S:\oim\Regular Reports\Vacancy Report &sysdate..xlsx";

rc= system(quote(catx(' ','copy',quote(trim(oldname)),quote(trim(newname)))));

put rc=;

run;


 

New Contributor
Posts: 2

Re: Copy Excel Workbook and Save Under New Name

Thank you.  I searched FCOPY, found this and it works.

 

filename src "path-to-src" recfm=n;
filename dst "path-to-dst" recfm=n;
%let rc = %sysfunc(FCOPY(src,dst));
%put %sysfunc(SYSMSG());

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 180 views
  • 2 likes
  • 2 in conversation