BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
edmb
Obsidian | Level 7

Hello all,

 

I use the following program to export a SAS dataset to an XLSX template workbook:

 

proc export 
data=work.dataset
file="/directory/Workbook Template"
dbms=XLSX
replace
label;
sheet='Data';

However, the next step I would like is for the the workbook to be copied (so I keep the original template) and rename the workbook just created with something like "Workbook &SYSDATE.xslx"

 

I have tried the solution to this post with no success and also tried the following code:

 

data _null_;
infile "/directory/Workbook Template.xlsx" lrecl=32767;
file "/directory/Workbook &RPT_DT_CHAR..xlsx";
input;
put _infile_;
run;

Yet this corrupts the workbook and renders it unopenable.

 

Does anyone have a solution to this problem that they could share with me please?

 

Regards,

 

Ed

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

An XLSX file is actually a ZIP file with lots of contents.  Hence reading/writing it as character will result in a corrupt file.  You need to read/write as byte per Chris's post here:

http://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhe...

 

To use datastep method.

 

As @Reeza has said you could use OS commands via X if that is enabled.  Alternatively just export the file twice.

View solution in original post

3 REPLIES 3
Reeza
Super User

Try an X command statement

 

x 'copy "path to file1" "path to new file"';

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

An XLSX file is actually a ZIP file with lots of contents.  Hence reading/writing it as character will result in a corrupt file.  You need to read/write as byte per Chris's post here:

http://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhe...

 

To use datastep method.

 

As @Reeza has said you could use OS commands via X if that is enabled.  Alternatively just export the file twice.

edmb
Obsidian | Level 7

Cheers to you both, though Chris's method in RW9's post worked the best for me.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 5372 views
  • 0 likes
  • 3 in conversation