Methods to Import data into SAS

Importing data into SAS is one of the basic concepts you need to know to work with data manipulation or analytics.

SAS can read data from almost any source. The Common data sources can be raw text files, Microsoft Office Excel spreadsheets, Access databases, and some popular database systems such as DB2 and Oracle.

Refer to the Supported Databases for Data Storage page for SAS’s complete list of supported databases.

Methods to import data into SAS

  • Using the infile statement.
  • Proc import
  • Filename statements

Infile Statement

A link between the program and the desired file is required to access a file from any programming language. Therefore, the INFILE statement is generally used in SAS to link to raw files.

INFILE also works with other SAS statements such as FILENAMEDATALINESPUT and INPUT to provide extensive data input and output in the DATA step.

INFILE Syntax:

INFILE file-specification ;
INFILE DBMS-specifications;


File specification identifies the source of the input data records, an external file or in-stream data.

Options: You can use many options on the infile statement.

Using the INFILE/FILE statement

Because the INFILE statement identifies the file to read, it must execute before the INPUT statement reads the input data records.

Because the INFILE statement identifies the file to read, it must execute before the INPUT statement reads the input data records.


We have a text file with data on vegetable seeds. Each line of the file contains the following pieces of information (separated by spaces):

vegetable Name, vegetable code, days to germination and number of seeds.

In SAS, each piece of information is called a variable (column in other systems). A few sample lines from the file are shown below:

Cucumber 50104-A 55 30 195 
Cucumber 51789-A 56 30 225 
Carrot 50179-A 68 1500 395 

Each data line produces what SAS calls an observation (also referred to as a row in other systems).

data veg;
infile "c:\books\learning\veggies.txt";
input Name $ Code $ Days Number Price;
Methods to Import data into SAS

The INPUT statement is one of SAS’s methods for reading raw data.

The default data delimiter for SAS is blank. However, SAS can also read data separated by any other delimiter (commas, tabs) with a minor change to the INFILE statement.

When you use the list input method for reading data, you only need to list the names you want to give each data value. SAS calls these variable names.

The INFILE statement tells SAS where to find the data, and the INPUT statement contains the variable names you want to associate with each data value.

The dollar sign($) following variable names tells SAS that values for Vegetable Name and code are character values.

Finally, the DATA step ends with a RUN statement.

Importing data into SAS using Proc Import

You can use the Proc import procedure to read excel data in SAS.


PROC IMPORT DATAFILE=filename OUT=sas-dataset DBMS=data-source-identifier REPLACE;

So, these are the ways to import data in SAS. We hope that you must have found it helpful.

You may also want to see our detailed guide on Importing data using Proc Import.

Moreover, if you have any other suggestions regarding other import methods, suggest us below in the comment section. We would take those lists in our further blog post.

Thanks for reading!

Every week we'll send you SAS tips and in-depth tutorials


Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.