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 the complete list of supported databases in SAS.
Page Contents
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 used in SAS to link to raw files generally.
INFILE also works with other SAS statements such as FILENAME, DATALINES, PUT and INPUT to provide extensive data input and output in the DATA step.
INFILE Syntax:
INFILE file-specification ;
INFILE DBMS-specifications;
Arguments
File specification identifies the source of the input data records, an external file or in-stream data.
Options: There are many options that you can use 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 that reads the input data records.
Because the INFILE statement identifies the file to read, it must execute before the INPUT statement that reads the input data records.
Example:
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 line of data 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;
run;

The INPUT statement shown here is one of SAS’s methods for reading raw data.
The default data delimiter for SAS is the blank. However, SAS can also read data separated by any other delimiter (for example, 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
To read excel data in SAS you can use the Proc import procedure.
Syntax:
PROC IMPORT DATAFILE=filename OUT=sas-dataset DBMS=data-source-identifier REPLACE; SHEET=sheet-name GETNAMES=Yes/No DATAROW=n; RANGE=range-values
RUN;
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 How to import data using Proc Import.
Moreover, if you have any other suggestions regarding other import methods, suggest us below the comment section. We would take those lists in our further blog post.
Thanks for reading!