9.6 Exporting SAS Data Sets with PROC EXPORT & the XLSX Engine
Key Takeaways
- PROC EXPORT writes a SAS data set to an external file and is the DATA-step-free alternative for producing raw data files.
- The DBMS= identifier selects the output format: CSV, TAB, DLM, JMP, and XLSX are the ones the content guide names.
- OUTFILE= names a physical file for delimited output while OUTTABLE= names a table inside a database or workbook.
- PUTNAMES=YES, the default, writes variable names as the first row; LABEL writes labels instead.
- The SAS/ACCESS XLSX engine assigned with LIBNAME lets a DATA step write worksheets directly, which is faster than PROC EXPORT when several sheets are involved.
9.6 Exporting SAS Data Sets with PROC EXPORT & the XLSX Engine
Quick Answer: The final objective in the Generate Reports and Output area is Export data, with two expanded bullets: create a simple raw data file using
PROC EXPORTas an alternative to the DATA step (controlling the format with the DBMS identifiers csv, jmp, tab, dlm), and export data to Microsoft Excel using the SAS/ACCESS XLSX engine.
PROC IMPORT reads external files in; PROC EXPORT writes SAS data sets out. Both infer as much as they can so that you never write an INPUT or PUT statement.
1. PROC EXPORT Syntax
PROC EXPORT DATA = libref.SAS-data-set <(data-set-options)>
OUTFILE = "physical-file-path" /* for delimited/raw files */
| OUTTABLE = "table-name" /* for database/workbook tables */
DBMS = identifier
<REPLACE>;
<PUTNAMES = YES | NO;>
<DELIMITER = 'character';>
<SHEET = "worksheet-name";>
<LABEL;>
RUN;
| Keyword | Purpose |
|---|---|
DATA= | The SAS data set to export; accepts data set options such as WHERE=, KEEP=, and OBS= |
OUTFILE= | Physical path of the file to create — used for CSV, TAB, DLM, JMP, and XLSX |
OUTTABLE= | Name of a table to create inside a database or a workbook |
DBMS= | The output format identifier |
REPLACE | Overwrite the target if it already exists; without it SAS refuses and writes an error |
Exam Trap: omitting
REPLACEwhen the target file already exists does not silently overwrite. SAS writesERROR: File already existsand produces nothing. Expect at least one distractor built on this.
2. The DBMS Identifiers Named by the Content Guide
DBMS= | Produces | Notes |
|---|---|---|
CSV | Comma-separated text | The default delimiter is a comma; PUTNAMES=YES by default |
TAB | Tab-delimited text | Equivalent to DLM with a tab character |
DLM | Delimited text with a delimiter you choose | Requires a DELIMITER= statement |
JMP | A JMP .jmp data table | For the SAS JMP statistical discovery application |
XLSX | A Microsoft Excel .xlsx workbook | Accepts a SHEET= statement to name the worksheet |
/* 1. Comma-separated values */
proc export data=work.final_report
outfile="C:\Reports\2026_Q1_Summary.csv"
dbms=csv
replace;
putnames=yes; /* variable names in row 1 - the default */
run;
/* 2. Tab-delimited text */
proc export data=work.final_report
outfile="C:\Reports\2026_Q1_Summary.txt"
dbms=tab
replace;
run;
/* 3. Pipe-delimited text */
proc export data=work.final_report
outfile="C:\Reports\2026_Q1_Summary.psv"
dbms=dlm
replace;
delimiter='|';
run;
/* 4. A JMP data table */
proc export data=work.final_report
outfile="C:\Reports\2026_Q1_Summary.jmp"
dbms=jmp
replace;
run;
/* 5. An Excel workbook with a named worksheet */
proc export data=work.final_report
outfile="C:\Reports\2026_Q1_Summary.xlsx"
dbms=xlsx
replace;
sheet="Q1 Summary";
run;
PUTNAMES= and LABEL
| Statement | Effect on the header row |
|---|---|
PUTNAMES=YES (default) | Writes variable names as the first row |
PUTNAMES=NO | Writes no header row — data begins on line 1 |
LABEL | Writes variable labels instead of names |
Exam Trap:
PUTNAMES=belongs toPROC EXPORTandGETNAMES=belongs toPROC IMPORT. The pairing is easy to remember from the direction of travel: you get names when reading in and put names when writing out.
Exporting a Subset
Because DATA= accepts data set options, no intermediate DATA step is needed:
proc export data=work.orders(where=(Region='West') keep=OrderID Amount OrderDate)
outfile="C:\Reports\west_orders.csv"
dbms=csv
replace;
run;
3. Exporting to Excel with the SAS/ACCESS XLSX Engine
The second expanded bullet asks specifically for the XLSX engine, which is a different mechanism from DBMS=XLSX. A LIBNAME statement with the XLSX engine treats a workbook as a SAS library: each worksheet becomes a member you can read or write with ordinary SAS code.
/* Assign the workbook as a library */
libname xlout xlsx "C:\Reports\CompanyData.xlsx";
/* Each DATA step creates or replaces a worksheet */
data xlout.Q1_Summary;
set work.final_report;
run;
data xlout.Q1_Detail;
set work.orders;
run;
/* PROC COPY writes several sheets at once */
proc copy in=work out=xlout;
select regional_totals product_mix;
run;
/* Clearing the libref closes the workbook and releases the file lock */
libname xlout clear;
| Approach | Best when |
|---|---|
PROC EXPORT ... DBMS=XLSX | A single data set becomes a single worksheet |
LIBNAME ... XLSX | Several worksheets are written, or DATA step and PROC COPY logic is involved |
ODS EXCEL | The output needs formatting — styles, titles, colours, autofilters |
Exam Trap: the XLSX engine writes raw data tables, not formatted reports. Titles, footnotes, and style templates are ignored. When a question mentions colours, embedded titles, or multiple tabs of formatted report output, the answer is
ODS EXCEL, not the XLSX engine.
Always clear the libref. Until LIBNAME xlout CLEAR; executes, SAS holds the workbook open and Excel cannot.
4. The DATA Step Alternative
PROC EXPORT is described in the content guide as an alternative to the DATA step, which implies knowing what it replaces. A DATA _NULL_ step with FILE and PUT gives complete control over the layout:
data _null_;
set work.final_report;
file "C:\Reports\manual_export.csv" dlm=',' dsd;
if _n_ = 1 then put "OrderID,Region,Amount"; /* hand-written header */
put OrderID Region Amount;
run;
| Consideration | PROC EXPORT | DATA _NULL_ with PUT |
|---|---|---|
| Lines of code | Minimal | Every column written explicitly |
| Header row | Automatic via PUTNAMES= | Hand-coded |
| Layout control | Limited to the DBMS= conventions | Total |
| Applies formats | Uses the variable's assigned format | Whatever you specify in the PUT |
| Fixed-width output | Not supported | Fully supported with column pointers |
Choose PROC EXPORT for standard delimited and Excel output, and the DATA step when the receiving system demands an exact layout.
Which PROC EXPORT step writes WORK.SALES to a pipe-delimited text file?
Which PROC EXPORT option controls whether variable names are written as the first row of the output file, and what is its default?
A programmer must write four SAS data sets into four worksheets of one Excel workbook using DATA steps. Which approach is the best fit?
A PROC EXPORT step targets a CSV file that already exists on disk, and the REPLACE option was omitted. What happens?
You've completed this section
Continue exploring other exams