Import Text Files into SAS Using PROC IMPORT
Importing data from text files into SAS (Statistical Analysis System) is a task that many data analysts encounter.
With the PROC IMPORT statement, you can seamlessly bring your text data into SAS for analysis.
Importing data from text files into SAS
This article will guide you through the process of using PROC IMPORT to import data from a text file, with a practical example included to enhance your understanding.
Basic Syntax of PROC IMPORT
The syntax for importing a text file using PROC IMPORT is straightforward and easy to follow. Here’s a general template you can utilize:
/* Import data from text file called data.txt */
proc import out=my_data
datafile="/path/to/your/data.txt"
dbms=dlm
replace;
getnames=YES;
run;
Explanation of Key Options
- out: This specifies the name to assign to the dataset in SAS once it has been imported.
- datafile: Here, you provide the path to the text file you wish to import.
- dbms: This option indicates the format of the file being imported. The
dlm
option assumes that spaces are used as delimiters. - replace: If a dataset with the same name already exists in SAS, this option will replace it.
- getnames: Setting this to
YES
instructs SAS to use the first row of the text file as variable names. If your text file does not have headers, set this option toNO
.
Practical Example of Importing a Text File
Let’s take a look at how to use this syntax with a practical example. Suppose you have a text file named data.txt. Here’s how to import this dataset into SAS:
/* Import data from text file called data.txt */
proc import out=new_data
datafile="/path/to/your/data.txt"
dbms=dlm
replace;
getnames=YES;
run;
/* View the imported dataset */
proc print data=new_data;
When executed, this code imports the contents of data.txt into SAS and stores it as new_data.

The output displayed in SAS will match exactly what is available in the text file, assuming the first line of your text file consists of variable names.
Important Notes
- Note #1: In this example, we used getnames=YES since the first row of data.txt contains column headers. If it did not, you would set this option to NO.
- Note #2: For more detailed information and to explore additional options available with PROC IMPORT, check the official SAS documentation.
Conclusion
Using the PROC IMPORT statement in SAS is an efficient way to import data from text files.
With the steps and example provided in this guide, you can easily integrate text file data into your SAS workflows.
Remember to adjust the options based on whether your text file contains headers or uses different delimiters.
For further reading and to improve your data handling skills, check out our resources on other import techniques in SAS, including importing CSV files and Excel sheets.
Happy analyzing!