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:
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 replace; delimiter = ' '; run;
When importing a space-delimited file, you need to do the following:
Filename txt_fl1 '/home/kisumsam/proc_import/txt_practice_01.txt'; proc import datafile=txt_fl1 out = txt_fl1 dbms = dlm replace; run;
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 replace; delimiter = ','; run;
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.
The delimiter in this file is a dollar sign ($).
** Remember to change the path in the FILENAME statement **;
Filename txt_fl3 '/home/your_user_name/proc_import/txt_practice_03.txt';
proc import datafile=txt_fl3
out = txt_fl3
dbms = dlm
delimiter = '$';