Table of Contents
SAS is a powerful statistical software that allows users to analyze and manipulate data. One of the key features of SAS is its ability to import data from various sources, including text files. Text files are simple, plain text documents that contain data in a structured or unstructured format.
To import text files into SAS, users can use the “IMPORT” procedure or the “IMPORT DATA” statement. This process involves specifying the location of the text file, the type of data contained within it, and the desired format for the imported data. SAS also allows users to customize the import process by specifying delimiters, data types, and other parameters.
Some common examples of text files that can be imported into SAS include CSV (Comma Separated Values) files, which are commonly used to store tabular data, and TXT (Plain Text) files, which can contain both structured and unstructured data. Other examples include log files, XML files, and JSON files.
By being able to import text files into SAS, users can easily integrate data from various sources into their analyses, allowing for a more comprehensive and accurate understanding of the data. This process also saves users time and effort by eliminating the need for manual data entry.
Import Text Files into SAS (With Examples)
You can use the PROC IMPORT statement to quickly import data from a text file into SAS.
This procedure uses the following basic syntax:
/*import data from text file called data.txt*/ proc import out=my_data datafile="/home/u13181/data.txt" dbms=dlm replace; getnames=YES; run;
Here’s what each line does:
- out: Name to give dataset once imported into SAS
- datafile: Location of text file to import
- dbms: Format of file being imported (dlm assumes spaces are used as delimiters)
- replace: Replace the file if it already exists
- getnames: Use first row as variable names (Set to NO if first row does not contain variable names)
The following example shows how to use this syntax in practice.
Example: Import Text File into SAS
Suppose we have the following text file called data.txt:

We can use the following code to import this dataset into SAS and call it new_data:
/*import data from text file called data.txt*/ proc import out=new_data datafile="/home/u13181/data.txt" dbms=dlm replace; getnames=YES; run; /*view dataset*/proc printdata=new_data;

The data shown in the SAS output matches the data shown in the text file.
Note #1: We used getnames=YES when importing the file since the first row of the text file contained variable names.
Note #2: You can find the complete documentation for the PROC IMPORT statement .
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can text files be imported into SAS, and what are some examples of this process?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-text-files-be-imported-into-sas-and-what-are-some-examples-of-this-process/
stats writer. "How can text files be imported into SAS, and what are some examples of this process?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-text-files-be-imported-into-sas-and-what-are-some-examples-of-this-process/.
stats writer. "How can text files be imported into SAS, and what are some examples of this process?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-text-files-be-imported-into-sas-and-what-are-some-examples-of-this-process/.
stats writer (2024) 'How can text files be imported into SAS, and what are some examples of this process?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-text-files-be-imported-into-sas-and-what-are-some-examples-of-this-process/.
[1] stats writer, "How can text files be imported into SAS, and what are some examples of this process?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can text files be imported into SAS, and what are some examples of this process?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
