Base SAS - Importing Data into SAS

How to read/Import data into SAS

This is the first article in the series of Base SAS that covers the very first thing that an analyst needs to learn in SAS.

Theoretically there are too many things to learn about it, but we are covering are those things which are  practically being used in the World of Analytics.

Let's start learning Base SAS

The way you are very particular in writing your name, SAS is too. 

Write your first SAS code

Data claim_data;
Input Gender $ Name $ Claim_amount ;
Male Naveen 10000
Male Mahesh 15000
Male Amit 7500
Female Neeta 18000
Female Geeta 12000


In the above code, you have read data written within SAS editor window. Practically, your data is too large to paste in editor window. Data resides in an external file, that you can import in SAS.

Download this data for using in below mentioned code   >>  Sample.txt

Use the following code .. please change the location with file location in your PC, in all the codes written across Base SAS articles.

Data claim_data ;
Infile  "Location\sample.txt";
Input  Gender $ name $ claim_amount


Let's now learn first SAS procedure

Let's import data using procedure in place of Data step. As such SAS doesn't do any distinction between Procedure and Data step .  It is just method of coding. Actually in the backend of Procedure, a Data step works.

Download this data for using in below mentioned code  >>   Sample_with_header.txt

Proc import  datafile"Location\sample_with_header.txt"
dbms=dlm replace
out=claim ;


Do use replace option always

Download this data for using in below mentioned code  >>  Exam_results.csv

proc import datafile"Location\exam_results.csv"
dbms = csv replace
out = class_10_result;
Getnames = yes;


proc import datafile“Location\exam_results.csv.csv"
dbms = csv replace
out = data;
Getnames = yes;
guessingrows = 200;


The code  in the log look geekish , however if you read it carefully, it is normal Data step ...with few additional options

Let's learn these options :

Informat : 

Define the way SAS need to read the data

Format :

Defines the way SAS needs to show the data


What is Delimiter ???

Value that separates two fields in a data

,    :      Tab     ~     &   -    ….so on

In SAS We write Tab as   – '09'X    

Download this data for using in below mentioned code  >>  claim_data_comma.csv

A very handy and Kool trick

Run Proc Import, copy the datastep written by the SAS in log.

Paste this code in Editor and then modify this … i.e. you can modify format and informat as per your requirement.

But this code with informat and informat is quite lengthy, is there method to abridge the same ?

Yes there is  ….

We can replace Informats with Informat modifier using Modified List input style.


Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.