Proc Import SAS CSV: Import CSV into SAS
A practical guide to importing CSV data into SAS using PROC IMPORT. Learn syntax, options, encoding handling, and troubleshooting for SAS 9.4 and SAS Viya to ensure robust CSV imports.

PROC IMPORT with DBMS=CSV is the SAS method for reading a comma-delimited file into a SAS data set. In most cases you specify an OUT data set and a FILENAME for the CSV, then use GETNAMES=YES to import header names. Optional options such as DATAROW, DELIMITER, and GUESSINGROWS tailor parsing and encoding for robustness.
Quickstart: Import a simple CSV with PROC IMPORT
If your goal is to bring a CSV into SAS quickly, use PROC IMPORT with DBMS=CSV. The keyword to remember is proc import sas csv. This approach reads the file into a SAS data set using the first row as variable names by default. The common workflow is to define an OUT dataset, point SAS to the file with DATAFILE (or a FILENAME reference), and enable GETNAMES=YES. For many users, this single block covers most everyday CSV imports, but you’ll likely tailor DATAROW and GUESSINGROWS as you validate data types and missing values.
filename csvfile '/path/to/data.csv' encoding='utf8';
proc import datafile=csvfile
out=work.imported_data
dbms=csv
replace;
getnames=yes;
datarow=2; /* first data row, after header */
run;In this example, the header row provides variable names, and the data begins on row 2. If the file has no header, set GETNAMES=NO and supply your own variable names in a subsequent DATA step.
Core syntax and options for CSV imports
The basic PROC IMPORT syntax for CSV is straightforward. You specify the datafile, the out dataset, and the DBMS. For reproducible workflows, you also set GETNAMES (to import header names) and DATAROW (to control where data begins). Additional controls include GUESSINGROWS, which adjusts type guessing, and DELIMITER when working with non-standard CSV files (though for CSV the comma is the default delimiter).
filename csvfile '/path/to/data.csv';
proc import datafile=csvfile
out=work.sample
dbms=csv
replace;
getnames=yes;
guessingrows=32767;
run;This block demonstrates a robust default; you can adjust GUESSINGROWS to improve datatype inference across larger files. If your dataset contains long strings or special characters, consider setting ENCODING on the FILENAME reference or within SAS session options.
Handling headers, datarow, encoding, and non-UTF-8 CSV
When the CSV uses a non-default encoding or header placement differs, you’ll want to tweak encoding and header handling. Using a FILENAME with encoding and a standard DATAROW helps SAS interpret the file correctly. If your CSV has a header row not in the first data row, DATAROW must be set accordingly. For UTF-8, you can attach encoding='utf8' to the FILENAME statement to preserve characters.
filename csvutf '/path/to/utf8-data.csv' encoding='utf8';
proc import datafile=csvutf
out=work.utf8_data
dbms=csv
replace;
getnames=yes;
datarow=2;
run;If you need to bypass the header, set GETNAMES=NO and later rename variables in a data step.
Import with nonstandard delimiter or large files (DLm vs CSV)
Although PROC IMPORT with DBMS=CSV assumes comma separation, many CSVs use semicolons or tabs. SAS can handle this by switching to a DELIMITER option in a DLm datafile or by using a data step with dlm option as an alternative import path. For truly large files, millions of rows, adjust GUESSINGROWS and use a streaming approach or a CAS-enabled workflow to keep memory usage in check.
filename csvdlm '/path/data_semicolon.csv' encoding='utf8';
proc import datafile=csvdlm
out=work.semicolon
dbms=dlm
replace;
delimiter=';';
getnames=yes;
datarow=2;
run;If you cannot change the delimiter, consider a data step to pre-split and then import, or preprocess the file to a standard CSV.
Validation, exploration, and quick checks after import
Once imported, validate structure and columns using PROC CONTENTS and inspect a few rows with PROC PRINT. This debugging step ensures that the inferred data types align with your expectations and that no columns were misread due to encoding or quoting. Always verify missing values and date formats after import.
proc contents data=work.imported_data; run;
proc print data=work.imported_data (obs=10); run;If you observe unexpected types or truncated strings, revisit GUESSINGROWS or switch to a more explicit data step approach to assert types.
Common pitfalls and practical tips for robust PROC IMPORT SAS CSV workflows
Beware of encoding mismatches, header misalignment, and stray punctuation in headers, which can derail automatic type guessing. When paths include spaces, enclose in quotes or assign a libname. For reproducibility, pin your SAS session encoding and prefer absolute file paths. Consider wrapping the import in a macro to parameterize file paths and outputs across environments.
%let infile=/path/to/data.csv;
%let outds=work.imported_data;
filename csv '&infile' encoding='utf8';
proc import datafile=csv out=&outds dbms=csv replace;
getnames=yes; datarow=2;
run;As MyDataTables notes, ensuring consistent encoding and header handling reduces errors in proc import sas csv workflows.
Best practices: reproducible, auditable CSV imports in SAS
Adopt a standard template for PROC IMPORT across projects. Keep input files in a dedicated data/ import directory, and track the file encoding in a README or metadata document. Validate after import with automated PROC CONTENTS checks and simple data quality rules. Finally, log your changes to support audit and collaboration.
Steps
Estimated time: 25-45 minutes
- 1
Identify file path and environment
Locate the CSV file you want to import and determine where SAS should write the output (WORK or a dedicated libname). Confirm encoding (UTF-8 is preferred) and whether headers exist in the first row. This planning reduces rework later.
Tip: Document the file path and encoding before coding to speed reproducibility. - 2
Write PROC IMPORT for a simple CSV
Create a PROC IMPORT block with GETNAMES=YES and DATAROW=2 to read headers and data from the second row. Use a FILENAME reference and set OUT to a SAS data set name you can reference later.
Tip: Use a descriptive dataset name and absolute paths when possible. - 3
Run and verify the import
Run the program and check the log for notes about successful import, variable types, and any warnings. Inspect the first few rows with PROC PRINT to confirm columns match CSV headers.
Tip: Look for notes about inferred types and missing values; adjust GUESSINGROWS if needed. - 4
Troubleshoot encoding or delimiters
If you encounter garbled text or misread columns, verify encoding and delimiter settings. Consider using DLm/DELIMITER for nonstandard CSV, or switch to a data step for full control.
Tip: When in doubt, preprocess the CSV to a standard delimiter and encoding.
Prerequisites
Required
- Required
- CSV file ready for import, encoded in UTF-8 or your target encodingRequired
- Basic SAS syntax familiarity (PROC IMPORT, DATA step)Required
- Filesystem access to the CSV file from SAS environmentRequired
- A SAS library (WORK or named libname) for the output datasetRequired
Optional
- Optional: a text editor to inspect headers or sample rowsOptional
Keyboard Shortcuts
| Action | Shortcut |
|---|---|
| Run current statementIn SAS Studio/EG or SAS Studio Editor | Ctrl+↵ |
| Submit all/Run entire programExecutes the full program in the editor | Ctrl+⇧+↵ |
| Comment/uncomment selectionToggle comments in SAS editor | Ctrl+/ |
| Find textSearch within the SAS editor or log | Ctrl+F |
| Open command paletteAccess commands in SAS Studio | Ctrl+⇧+P |
People Also Ask
What is PROC IMPORT used for in SAS?
PROC IMPORT reads external data files into SAS data sets. When the source is CSV, you typically use DBMS=CSV with options like GETNAMES and DATAROW to control header handling and the starting data row.
PROC IMPORT brings external CSV data into SAS as a data set, using the header row as variable names.
Can PROC IMPORT infer data types automatically?
Yes, automatic type guessing can occur when GETNAMES is enabled and GUESSINGROWS is set high enough. After import, use PROC CONTENTS to review inferred types and adjust as needed.
SAS can infer types during import, but you should verify with contents to ensure accuracy.
How do I handle non-UTF-8 CSV files?
If a CSV uses a different encoding, specify an encoding in the FILENAME statement (or convert the file to UTF-8 before import). This helps preserve special characters.
If encoding is off, set the encoding on the file reference so SAS reads characters correctly.
What if my CSV has no header row?
Set GETNAMES=NO and provide your own variable names in a subsequent DATA step or use RENAME statements. You may also create a header row in a preprocessing step.
No header? Import without names, then rename variables after import.
How can I import very large CSV files efficiently?
For large files, increase GUESSINGROWS and consider using the DLm engine for specific delimiters or processing the file in chunks. In SAS Viya, CAS-enabled workflows can help with memory management.
Large CSVs may need chunking or alternative engines for better performance.
Main Points
- Use PROC IMPORT with DBMS=CSV to load CSVs into SAS
- GETNAMES=YES imports header names automatically
- DATAROW controls where data starts; adjust for headers
- Always validate with PROC CONTENTS and sample PROC PRINT