SASCRUNCH TRAINING
  • Home
  • SASĀ® Certification Training
    • SAS Certified Specialist Exam Training Program
    • How to Prepare For SAS Certified Specialist Base Programming Exam
  • Online Courses
    • Practical SAS Training Course for Beginners
    • Proc SQL Course
    • SAS Project Training Course
    • Logistic Regression (Credit Scoring) Modeling using SAS
  • Articles
    • Get Started >
      • 18 Free Resources to Help You Learn SAS
      • SAS Tutorial
      • How to Install SAS Studio
      • How to Learn SAS Fast
    • Data Import >
      • Importing Excel Spreadsheet
      • Importing CSV Files
      • Importing Text Files
    • SAS Functions >
      • CAT, CATT, CATS, CATX Functions
      • If-Then-Else statement
      • TRIM Function
      • STRIP Function
      • YEAR, MONTH, DAY Functions
      • Compress Function
      • Do-Loop
      • SCAN Function
      • LIKE Operator
      • INDEX Function
    • Data Manipulations >
      • The Ultimate Guide to Proc SQL
      • Proc Datasets
      • Dictionary Tables
      • Dealing with Missing Values
      • Proc Compare
      • Proc Transpose
      • RETAIN Statement
      • SAS Formats
      • SAS Arrays
    • Statistical Analysis >
      • Proc Means
      • Proc Freq
      • Proc Tabulate
    • Informational Interviews >
      • Senior Recruiter at a Fortune 500 Retail Company
      • Manager, Non-profit Health Services Research
      • HR Manager
      • Quantitative Analyst
  • Services
    • The Ultimate Job Search Automation Services
    • Statistical Consulting
    • SAS Project or Assignment Help
    • Data Import Services
    • Data Manipulation and Reporting Services
  • In-class Training
    • SAS Training for Job Seekers
  • Guest Lecture
  • Sample Resume
  • About us
  • Contact Us
Master SAS
​in 30 Days
Start your Free training now!
x
Picture
Need help studying for the new
SAS Certified Specialist Exam?
Get access to:
  • Two Full Certificate Prep Courses
  • ​300+ Practice Exercises
Start your free training now
How to Prepare for the SAS Certified Specialist Base Programming Exam
Picture
 
Lesson 3.2: Importing data from CSV file
IMPORTANT! This tutorial is updated on March 9, 2017. See the latest training on importing CSV files into SAS. 


This section will explain how to import data from a csv file. There are two ways to do this: Proc Import or Data Step with an Infile Statement.


2. CSV

Example

Below is the csv file that I am going to read into SAS:
Picture

PROC IMPORT DATAFILE="C:\test.csv"
  OUT=SASCrunch
  DBMS=csv
  REPLACE;
  GETNAMES=Yes;

RUN;
Picture
As you can see, it is very similar to importing data from an excel file. You just need to change the DBMS to ‘csv’ and use the correct extension (csv) on the data file.

Now, let’s take a look at the dataset that we have just created: 
Picture
Another way to import a csv file into SAS is to use the infile statement. The infile statement allows more flexibility in terms of assigning attributes to the data imported. Attributes will be explained in later lessons.

Example

Let’s import the same file using the infile statement. 



DATA SASCrunch;
    INFILE "C:\test.csv" 
    DELIMITER = ","
    MISSOVER DSD 
    FIRSTOBS=2 
    LRECL=32767;

    INPUT Name $ Score;

RUN;

Picture

Let's break down each statements above:

(1) INFILE statement identifies the path to the external datafile.

(2) DELIMITER identifies which delimiter to use. In a CSV (Comma-Separated Value) file, a delimiter will be, well obviously, a comma!

(3) <IMPORTANT> MISSOVER and DSD are two important function when using the INFILE method to import the data. They allow SAS to read a missing value rather than skipping it. If these two functions are not specified, a missing value will could cause tremendous errors when importing the data!

(4) FIRSTOBS=2 tells SAS to start reading the data from the second row. 

(5) <Optional> LRECL assigns the Logical Record Length to the value captured. The default value is 256 and it is normally sufficient to capture most of the data. However, for a long string of text, a larger value can be assigned through the LRECL= option. The range for lrecl is 1 to 32767.

DONE! You have learned how to import data from a CSV file.

Again, you do not have to memorize the codes. Copy us and modify the path whenever you need to import a csv file! 
Previous
Next

    Have a Question?

Submit
 

Master SAS in 30 Days

Start your Free training now!
Copyright © 2012-2019 SASCrunch.com All rights reserved.
  • Home
  • SASĀ® Certification Training
    • SAS Certified Specialist Exam Training Program
    • How to Prepare For SAS Certified Specialist Base Programming Exam
  • Online Courses
    • Practical SAS Training Course for Beginners
    • Proc SQL Course
    • SAS Project Training Course
    • Logistic Regression (Credit Scoring) Modeling using SAS
  • Articles
    • Get Started >
      • 18 Free Resources to Help You Learn SAS
      • SAS Tutorial
      • How to Install SAS Studio
      • How to Learn SAS Fast
    • Data Import >
      • Importing Excel Spreadsheet
      • Importing CSV Files
      • Importing Text Files
    • SAS Functions >
      • CAT, CATT, CATS, CATX Functions
      • If-Then-Else statement
      • TRIM Function
      • STRIP Function
      • YEAR, MONTH, DAY Functions
      • Compress Function
      • Do-Loop
      • SCAN Function
      • LIKE Operator
      • INDEX Function
    • Data Manipulations >
      • The Ultimate Guide to Proc SQL
      • Proc Datasets
      • Dictionary Tables
      • Dealing with Missing Values
      • Proc Compare
      • Proc Transpose
      • RETAIN Statement
      • SAS Formats
      • SAS Arrays
    • Statistical Analysis >
      • Proc Means
      • Proc Freq
      • Proc Tabulate
    • Informational Interviews >
      • Senior Recruiter at a Fortune 500 Retail Company
      • Manager, Non-profit Health Services Research
      • HR Manager
      • Quantitative Analyst
  • Services
    • The Ultimate Job Search Automation Services
    • Statistical Consulting
    • SAS Project or Assignment Help
    • Data Import Services
    • Data Manipulation and Reporting Services
  • In-class Training
    • SAS Training for Job Seekers
  • Guest Lecture
  • Sample Resume
  • About us
  • Contact Us