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

Hi all!

 

I'm facing some problems when exporting data with the code bellow

In the first time it works well but from the second on it add a new sheet to the file instead  of replace it a create also a new file with the same name but format .BAK

Please help me, i want export data to several places that's why i don't want to use the predefined exporting ways.

proc export 
  data=WORK.DCE_RACIO
  dbms=xlsx 
  outfile="\\file1\DNV\06_OUTRAS_DIR\DCE\Apólices.xlsx" 
  replace;
run;

 

Cheers

1 ACCEPTED SOLUTION

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

I would recommend you use either ods tagsets.excelxp, or libname excel.  For an example:

ods tagsets.excelxp file="c:\your_fie.xml" options(sheet_name="First Sheet");
proc report data=....
run;

ods tagsets.excelxp options(sheet_name="Second Sheet");
proc report data...
run;

ods tagsets.excelxp close;

Help:

https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html

 

Note that this creates XML output which Excel can read.  Libname excel is available in 9.4:

http://www2.sas.com/proceedings/sugi31/024-31.pdf

 

Other than for basic tasks, proc export wouldn't be my first choice.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would recommend you use either ods tagsets.excelxp, or libname excel.  For an example:

ods tagsets.excelxp file="c:\your_fie.xml" options(sheet_name="First Sheet");
proc report data=....
run;

ods tagsets.excelxp options(sheet_name="Second Sheet");
proc report data...
run;

ods tagsets.excelxp close;

Help:

https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html

 

Note that this creates XML output which Excel can read.  Libname excel is available in 9.4:

http://www2.sas.com/proceedings/sugi31/024-31.pdf

 

Other than for basic tasks, proc export wouldn't be my first choice.

Uriel
Calcite | Level 5
RW9 many thank for your answer;

As a new one, I'm afraid i have to study more in order to aply your sujection (help).

Cheers!!
k_o
Fluorite | Level 6 k_o
Fluorite | Level 6

Regarding:  In the first time it works well but from the second on it add a new sheet to the file instead  of replace it

 

You need to specify the sheet option to replace a specific sheet, for example:

 

proc export 
  data=WORK.DCE_RACIO
  dbms=xlsx 
  outfile="\\file1\DNV\06_OUTRAS_DIR\DCE\Apólices.xlsx" 
  replace;
  sheet="DCE_RACIO";
run;

 

However, I do agree with the accepted solution that ODS output is best and most versatile - but it is also very complicated as you noticed.

 

Regarding the new file that is created:  this is what happens when you attempt to create a file that already exists.  SAS automatically renames the existing file to save it for you, by replacing the file extension with ".bak".

 

You can enhance proc export by putting it inside a macro or do loop, and then using macro variables in the file name, you can output multiple files fairly easy.

 

 

Uriel
Calcite | Level 5
k_o
Many thanks for the hint, the problem keeps but at least i can name the sheets while i learn how to use ODS

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2233 views
  • 1 like
  • 3 in conversation