How to Import a TXT File into SAS (Step-by-Step Guide for Beginners)
If you’re working with data in SAS, chances are you’ll need to import a TXT file at some point. Whether it’s survey responses, transaction logs, or exported reports, plain text files are a common format for raw data.
This guide will show you how to import a TXT file into SAS using both the DATA step and PROC IMPORT methods – perfect for beginners who want clean, organized data inside SAS.
Before You Start: Know Your File Format
TXT files come in different shapes and sizes. The two most common formats are:
- Delimited (e.g., tab-separated, comma-separated)
- Fixed-width (each field has a fixed number of characters)
Check your TXT file in a text editor like Notepad or VS Code to understand its structure. That will determine which method you use.
What Is a Delimiter?
A delimiter is a character or symbol used to separate individual pieces of data in a text file—especially in plain text formats like .txt
or .csv
.
Think of a delimiter as the “separator” between data values. It helps programs like SAS know where one value ends and the next one begins.
Using PROC IMPORT
Let’s use data from the TXT file below as an example for this tutorial. The data has imaginary names and test scores which are separated by a space.

To import this TXT file, we could use the PROC IMPORT code below.

What This Does:
OUT=
names your new SAS datasetDATAFILE=
points to your TXT fileDBMS=dlm
tells SAS it’s a delimited fileDELIMITER=
dlm sets space as the delimiter
Since our test data was neatly formatted with single-space delimiters, the data was successfully imported and resulted in the SAS dataset below.

What If My Data Is Delimited by Something Other Than Single Space?
No worries! SAS gives you the flexibility to import text files delimited by almost any character—not just spaces. You simply need to adjust the DELIMITER=
option within your PROC IMPORT
statement.
Below is a handy reference table showing common delimiters and how to specify them correctly in SAS:
Delimiter | Symbol | Delimiter = |
---|---|---|
Comma | , | ‘,’ |
Tab | (tab) | ’09’x |
Pipe | ` | ‘|’ |
Semicolon | ; | ‘;’ |
Space | ‘ ‘ | |
Custom | ~ , ^ , # | 'character' (e.g., '@' ) |
Tips & Troubleshooting
- Missing Values: Watch out for missing delimiters or short fields—they can shift your data.
- Preview First: Use a small test file to confirm your import setup before loading huge datasets.
- Log Warnings: Always check the SAS log for warnings or truncation issues.
If you need help or want tips on importing a CSV file into SAS, I have a how to guide on that here.
Importing a .txt
file into SAS using PROC IMPORT
is a powerful and efficient way to get started with data analysis. By simply specifying the correct DBMS
and DELIMITER
options, you can handle a wide range of file formats—from tab-delimited logs to pipe-separated system exports.
Got Questions?
If you run into issues or want help with a tricky file format, feel free to drop a comment below or reach out! I’m happy to help troubleshoot and offer tailored code examples.
Thanks for reading—and happy coding in SAS!