Export CSV from SAS with the required delimiter

How to export CSV and other delimited files from SAS with PROC EXPORT or a DATA step, what the delimiter setting changes, and how to check the file works where it's going.

Exporting a SAS dataset to CSV is usually one short PROC EXPORT step. It gets harder when the receiving system needs something other than a comma, such as a semicolon, a pipe or a tab. This review covers which SAS approach fits each case, what changing the delimiter actually does to the file, and what to check before you send it on.

Evidence note: no tested output files, SAS release details or destination-specific results were supplied for this article. The guidance below is based on documented SAS syntax and general behavior of delimited text. Test it in your own SAS environment and with your actual destination before relying on it.

Is a custom delimiter the right choice?

Use a plain comma-separated file unless the receiving system asks for something else. Comma CSV is the most widely expected format, and most import tools handle it without extra configuration. A different delimiter only helps when a specific consumer requires it.

  • A semicolon suits regional spreadsheet settings where the comma is the decimal separator.
  • A pipe suits data loads whose text fields often contain commas.
  • A tab suits tools that expect TSV, or files that people will paste into spreadsheets.

The main tradeoff is portability. A non-comma file is fine for a known consumer, but less predictable when you share it widely, especially if it still uses the .csv extension. If you don't know who will open the file, a standard comma CSV with proper quoting is the safer default.

Option 1: PROC EXPORT with DBMS=CSV for a standard comma file

proc export data=work.sales
    outfile="/path/to/sales.csv"
    dbms=csv
    replace;
    putnames=yes;
run;

DBMS=CSV writes comma-separated values. REPLACE overwrites an existing file at the same path. PUTNAMES=YES writes variable names as the header row, and PUTNAMES=NO leaves the header out. Values that contain the delimiter are enclosed in double quotes, so embedded commas do not break the column structure.

Option 2: PROC EXPORT with DBMS=DLM and a DELIMITER statement

For any delimiter other than a comma, the documented approach is DBMS=DLM combined with a DELIMITER statement.

proc export data=work.sales
    outfile="/path/to/sales.txt"
    dbms=dlm
    replace;
    delimiter='|';
    putnames=yes;
run;

For a semicolon, use delimiter=';'. For a tab, you can write the character as a hexadecimal constant, or use DBMS=TAB, which produces tab-delimited output directly.

/* Tab via hexadecimal constant (ASCII-based systems) */
proc export data=work.sales
    outfile="/path/to/sales.tsv"
    dbms=dlm
    replace;
    delimiter='09'x;
run;

/* Tab via the TAB identifier */
proc export data=work.sales
    outfile="/path/to/sales.tsv"
    dbms=tab
    replace;
run;

The '09'x constant assumes an ASCII-based environment. On an EBCDIC host the tab character has a different code, so DBMS=TAB is the more portable choice for tabs. Some users report that a DELIMITER statement also takes effect with DBMS=CSV, but this has not been verified here. DBMS=DLM is the form that clearly matches the documented intent.

Option 3: A DATA step with FILE and DLM= for full control

When you need precise control over formats, column order or missing-value output, a DATA step is more explicit than PROC EXPORT.

filename out "/path/to/sales.txt" encoding="utf-8" termstr=crlf;

data _null_;
    set work.sales;
    file out dlm='|' dsd;
    if _n_ = 1 then put 'region|product|amount|sale_date';
    put region product amount sale_date :yymmdd10.;
run;

Here is what each part of that example does:

  • DLM= sets the separator.
  • The DSD option quotes values that contain the delimiter and treats delimiters as strict field boundaries.
  • The header is written by hand on the first iteration, so it must match the PUT list exactly.
  • The date is written with an explicit format, so it does not appear as a raw SAS date number.
Approach | Delimiter control | Header row | Best fit
PROC EXPORT, DBMS=CSV | Comma only (documented) | PUTNAMES= | Standard CSV for general sharing
PROC EXPORT, DBMS=DLM | Any single character via DELIMITER | PUTNAMES= | Quick non-comma export of a whole dataset
PROC EXPORT, DBMS=TAB | Tab | PUTNAMES= | TSV output
DATA step with FILE and DLM= | Any delimiter, plus per-variable formats | Written manually | Strict layouts, selected columns, custom value formatting

What changing the delimiter actually changes

Choosing a delimiter changes the characters stored in the file. It is not a display setting. The separator byte between fields is different, and the quoting rules depend on that separator. With a pipe delimiter, a value containing a comma is plain text and needs no quotes. A value containing a pipe must be quoted.

The delimiter setting does not change your data values, but other settings in the same export can:

  • Formats: PROC EXPORT writes formatted values when a format is attached to a variable, so a date may appear as text such as a day-month-year string rather than a number.
  • Format widths: a variable with a short format width can be truncated or rounded in the output.
  • Labels: the LABEL option on PROC EXPORT uses variable labels instead of names in the header row.

Check formats, widths and labels whenever exact values matter.

Missing values need checking too. In DATA step output, a missing numeric value is written as the character set by the MISSING= system option, which is a period by default. The receiving system may read that period as text rather than as empty. Open a sample of the output and confirm how missing numeric and character values appear before you rely on the default.

Encoding and line endings

The bytes written for accented and non-Latin characters depend on the SAS session encoding, or on the ENCODING= option of a FILENAME statement when you write through a fileref. If the destination expects UTF-8 and your session uses a different encoding, characters outside basic ASCII can be garbled after import.

The TERMSTR= option on FILENAME sets the line ending, for example CRLF for Windows-oriented consumers or LF for Unix-oriented ones. Neither encoding nor line endings depend on the delimiter, but both affect whether the file imports cleanly.

Some spreadsheet applications use a byte order mark to recognize UTF-8 in CSV files. Whether your SAS configuration writes one, and whether your destination needs one, was not tested here. Check both with a file that contains non-ASCII characters.

Will the file stay usable after sharing?

A delimited file is plain text, so copying, emailing or moving it does not alter its contents. Problems usually appear when someone opens it.

  • Spreadsheet applications may choose a separator based on the file extension or regional list-separator settings. A pipe- or semicolon-delimited file named .csv can therefore open as a single column on some systems.
  • Giving non-comma files an extension such as .txt or .tsv, and stating the delimiter when you share the file, reduces guesswork.
  • Using the import wizard and choosing the delimiter explicitly is more reliable than double-clicking the file.
  • No specific application or version was tested for this article, so treat these as things to verify, not guaranteed outcomes.

Accessibility depends on how the file is opened:

  • In a text editor, a screen reader reads delimiters as characters, and long rows are hard to follow.
  • When the file is imported into a spreadsheet or rendered as a table, assistive technology can usually move cell by cell, which is easier for readers.
  • If people will read the data directly rather than load it, consider also providing a short summary or an accessible table alongside the raw file.
  • No assistive technology was tested here.

Searching and editing work on the raw text. A search for a value finds it whatever the delimiter. Editing by hand is risky with any delimiter, though, because an added or removed separator shifts every later field in that row.

Checks before you hand the file over

  • Confirm the delimiter the destination expects, and whether it expects a header row.
  • Check that values containing the delimiter, quotes or line breaks are quoted correctly in the output.
  • Confirm that dates, decimals and formatted numbers appear as the destination expects.
  • Check how missing values are written.
  • Match the encoding and line endings to the destination.
  • Test-import a sample with the actual receiving tool rather than assuming it will work.

Bottom line

For a standard comma file, use PROC EXPORT with DBMS=CSV. For a semicolon, pipe or other single-character delimiter required by a known consumer, use DBMS=DLM with a DELIMITER statement, or DBMS=TAB for tabs. Switch to a DATA step when formats, column selection or missing-value output must be exact. Keep to a plain comma CSV when the audience is unknown, since a non-default delimiter only pays off when the receiving system expects it.