Desktop productivity for business analysts and programmers

Problems while exporting Data

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Problems while exporting Data

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


Accepted Solutions
Solution
‎04-05-2016 06:18 AM
Super User
Super User
Posts: 7,720

Re: Problems while exporting Data

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


All Replies
Solution
‎04-05-2016 06:18 AM
Super User
Super User
Posts: 7,720

Re: Problems while exporting Data

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.

New Contributor
Posts: 4

Re: Problems while exporting Data

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!!
Occasional Contributor k_o
Occasional Contributor
Posts: 5

Re: Problems while exporting Data

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.

 

 

New Contributor
Posts: 4

Re: Problems while exporting Data

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
☑ This topic is solved.

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

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