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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.