Export SAS data to CSV with PROC EXPORT
How PROC EXPORT writes a SAS dataset to CSV, what changes when it does, and what to check so the file stays readable and usable.
PROC EXPORT is the standard SAS procedure for writing a dataset to a delimited text file. With DBMS=CSV it produces a comma-separated file that spreadsheets, databases, scripting languages and other statistics tools can read. This review covers what the conversion changes, where meaning can be lost, and when a different approach is better. It is based on documented SAS behavior and general CSV principles. No test results for specific SAS releases, operating systems or receiving applications were supplied, so behavior that varies by environment is flagged rather than asserted.
The basic export
A minimal SAS export to CSV names the input dataset, the output file and the file type. REPLACE allows SAS to overwrite an existing file at that path. Without it, the procedure will not overwrite and writes a note to the log instead.
proc export data=work.sales
outfile="/project/output/sales.csv"
dbms=csv
replace;
run;
The output path is resolved on the machine where SAS runs. In server-based setups such as SAS Studio, that is the server, not your desktop. Check the log after every run: it reports how many records were written and shows any warnings about the file.
Is CSV export suitable for your use?
For moving tabular values into another tool, CSV export is usually a sound choice. The main benefit is portability: the result is plain text with one row per observation and one field per variable, and almost any data tool can read it. The decisive tradeoff is that CSV carries values only. SAS metadata such as variable types, lengths, formats, informats and labels is not preserved as metadata. A receiving program has to guess types or be told them.
- Good fit: handing data to a spreadsheet user, loading into a database or script, or archiving values in a tool-neutral form.
- Weaker fit: round-tripping data back into SAS when exact types, lengths and formats matter. A SAS dataset or transport file keeps that information. CSV does not.
- Weaker fit: data with leading zeros, long identifiers or ambiguous dates that will be opened directly in a spreadsheet. The spreadsheet may reinterpret those values when it opens the file.
- Prefer a different route: when you need custom quoting, per-column control or unusual layouts, a DATA step with a FILE statement gives finer control than PROC EXPORT.
What the export actually changes
PROC EXPORT serializes stored values into delimited text. It does not reverse, mirror or restyle characters. The word "format" in SAS is a source of confusion here. A SAS format is a rule for displaying a value, such as showing a date number as a calendar date. It has nothing to do with fonts or visual styling. A CSV file has no fonts, colors or column widths, so none of those appear in the output.
Formats do matter, though, because PROC EXPORT generally writes the formatted value of each variable. SAS stores dates as the number of days since January 1, 1960. A date variable with a date format is written as readable text. The same variable without a format is written as a bare number that will mean little to the recipient. The reverse also applies: a format that rounds or groups values writes the rounded or grouped text, not the underlying stored value. Before exporting, review the formats attached to each variable, for example with PROC CONTENTS, and change or remove any that would hide precision you need.
- Header row: by default the first line contains variable names.
- Labels: adding the LABEL option to the PROC EXPORT statement writes variable labels as headers instead of names.
- Delimiters inside values: character values that contain a comma are enclosed in double quotes so the field boundaries stay intact. Embedded double quotes are doubled, following common CSV convention.
- Missing values: confirm how missing numeric and character values appear in your output. The MISSING= system option affects how missing numerics are displayed, and receiving tools differ in how they read an empty field compared with a period.
Useful options and variations
| Need | How to do it in PROC EXPORT | Note |
| No header row | PUTNAMES=NO; statement | Supported for delimited files in SAS 9.4 releases. Confirm in your version's documentation. |
| Labels as headers | LABEL option on the PROC EXPORT statement | Labels may contain spaces or punctuation that some importers handle poorly. |
| Tab-separated output | DBMS=TAB | Writes TSV instead of CSV. |
| Other delimiter, such as semicolon | DBMS=DLM with a DELIMITER= statement | Common where the comma is the decimal separator. |
| Subset rows or columns | WHERE=, KEEP= or DROP= dataset options on DATA= | Filters at export time without changing the source dataset. |
| Specific encoding or line endings | Point OUTFILE= at a fileref defined with ENCODING= or TERMSTR= | See the example below. |
proc export data=work.sales(where=(region='West') keep=id region amount)
outfile="/project/output/west.txt"
dbms=dlm
replace;
delimiter=';';
putnames=yes;
run;
Will the file stay readable after sharing?
A CSV file is plain text, so copying it, emailing it or opening it in a text editor does not alter the stored characters. The problems usually come from how the receiving tool interprets the file, not from the file itself.
- Encoding: the file is written in the SAS session encoding unless you specify otherwise. If the data contains accented letters, non-Latin scripts, combining marks or emoji, a mismatch between the export encoding and the importer's assumption can corrupt those characters. Specifying UTF-8 explicitly is the safer default when the destination supports it.
- Spreadsheet reinterpretation: opening a CSV directly in a spreadsheet can strip leading zeros, convert long digit strings to rounded numbers, or turn text that resembles a date into a date. The CSV is unchanged on disk, but saving from the spreadsheet can make the change permanent. Using the spreadsheet's import feature with column types set to text avoids this.
- Line endings: files written on Linux or UNIX use LF line endings by default. Most modern tools accept either LF or CRLF. If a destination requires CRLF, set TERMSTR=CRLF on the FILENAME statement.
- Right-to-left text: values in scripts such as Arabic or Hebrew are stored in logical order. How they display depends on the viewer's bidirectional text handling, not on the export.
- Accessibility: a raw CSV has no table structure for assistive technology, so a screen reader in a text editor reads it as delimited lines. A clear header row and meaningful column names help. If people will read the data rather than process it, presenting it as a proper table in a spreadsheet or document is more usable. No assistive-technology testing was supplied for this article.
filename out "/project/output/sales.csv" encoding="utf-8" termstr=crlf;
proc export data=work.sales
outfile=out
dbms=csv
replace;
run;
Checks before you rely on the file
- Read the SAS log for the record count and any warnings.
- Open the CSV in a plain text editor, not only a spreadsheet, to see exactly what was written.
- Compare a few rows against the source, especially dates, decimals, identifiers with leading zeros and missing values.
- Confirm the header row matches what the receiving system expects: names or labels, present or absent.
- Test an import in the actual destination. A clean result in one tool does not guarantee the same result in another.
Verdict
PROC EXPORT with DBMS=CSV is a dependable, low-effort way to get SAS data into a widely readable form, and the defaults are reasonable for most handoffs. Its limits come from CSV itself: the file keeps values but not SAS metadata, it writes formatted rather than raw values, and its encoding and the destination tool's behavior determine whether special characters and identifiers survive. Check formats and encoding before exporting and verify the file in its real destination. Keep data in SAS's native format when the next step is SAS itself, and use a DATA step when you need control that PROC EXPORT does not offer.