Skip to content
9to5sas
  • Index
  • Glossary
Facebook Twitter Instagram Email RSS

  • Start Here
  • Base SAS
  • Advanced SASExpand
    • SAS Macros
    • PROC SQL
  • SAS/STATSExpand
    • SAS Analytics
    • Statistics
  • SAS Programs
9to5sas

9to5sas » Base SAS » Methods to Import data into SAS

Methods to Import data into SAS

BySubhro Posted onNovember 19, 2019August 31, 2022 Last Updated:August 31, 2022
0 Comments

Importing data into SAS is one of the basic concepts you need to know in order to work with data manipulation or analytics. SAS can read data from almost any source. Common data sources can be raw text files, Microsoft Office Excel spreadsheets, Access databases, and some of the popular database systems such as DB2 and Oracle.

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 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: 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.

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 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;
run;
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.

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 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

JOIN OUR COMMUNITY OF SAS Programmers!

Check your inbox or spam folder to confirm your subscription.

Post Tags: #import in sas dataset#import in sas from excel#import in sass
Subhro

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.

Facebook Twitter Linkedin

Post navigation

Previous Previous
History of SAS software
NextContinue
Data set Options in SAS

SAS Tips in your inbox

Subscribe to 9to5sas for timely SAS tips and news delivered each month.
Learn about the latest articles, and code samples to keep your SAS skills fresh!

Your subscription is successful!

Recent Posts

  • Concatenate strings in SAS: The CAT Functions Demystified
  • 5 Techniques for Quickly Removing Leading Zeros in SAS
  • Troubleshoot Your Proc SQL Code Like a Pro with These 7 Automatic Macro Variables
  • 7 PROC SQL Options You Should Use to Debug Queries
  • How To Use The SAS Proc SQL Order By Statement?
9to5sas
  • Privacy Policy
  • Disclaimer
  • About
  • Contact
Facebook Twitter Instagram RSS Email Pinterest

Copyright © 2023 9TO5SAS, All rights reserved.

Scroll to top
  • 9to5sas Blueprint
  • About
  • About
  • Acceptable use policy
  • calculator
  • Confirm email
  • Contact
  • Contact
  • Cookie Policy
  • DISCLAIMER
  • Getting Started with SAS
  • Glossary
  • Index
  • Post #13801
  • Privacy Policy
  • Privacy policy
  • SAS Programs
  • Styles
  • Subscription confirmed
  • Terms and conditions
  • Thank You