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
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.
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.
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.
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.
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.