Proc Import [4-7]


Importing a Text Delimited File

A text file is another file type that can be imported using Proc Import.

Let's look at the txt_practice_01.txt file.

The text file contains three columns:

  • Name
  • Age
  • Gender

The file is also a space-delimited file, which means the values are all separated by a single space.

Let's look at the code to import this file:

Filename txt_fl1 '/home/kisumsam/proc_import/txt_practice_01.txt';

proc import datafile=txt_fl1
  out = txt_fl1
  dbms = dlm
  delimiter = ' ';

When importing a space-delimited file, you need to do the following:

  1. Specify DLM as the DBMS option
  2. Optionally, specify the space as the delimiter. 


  • The Delimiter statement is optional for space-delimited files. SAS, by default, assumes the delimiter to be a space. You do not need to specify it when importing a space-delimited file.
Filename txt_fl1 '/home/kisumsam/proc_import/txt_practice_01.txt';

proc import datafile=txt_fl1
  out = txt_fl1
  dbms = dlm

The code above, without the Delimiter statement, will import the text file just fine:

Programming Tip 3

When importing a text file, there are two DBMS options that you can specify:

DBMS=DLM is used for all kinds of text files except for tab-delimited files

DBMS=TAB is used for tab-delimited files

​You will learn more about this in the next section.

Comma Delimited Files

Importing a comma-delimited file is similar to importing a space-delimited file. 

Let's take a look at the text file named txt_practice_02.txt:

The file is a comma-delimited text file, and each value is separated by a comma.

​Below is the code to import this file:

Filename txt_fl2 '/home/kisumsam/proc_import/txt_practice_02.txt';

proc import datafile=txt_fl2
  out = txt_fl2
  dbms = dlm
  delimiter = ',';

The Delimiter statement tells SAS the file is a comma-delimited file.

SAS will then import the file accordingly:

In the next section, we will learn how to import a tab-delimited file.


Use Proc Import to import the file named txt_practice_03.txt.

Get Hint

Get Solution