Notice! This document is currently in
Archived
status.
The content of this document may be incorrect or outdated.
The content of this document may be incorrect or outdated.
Print this article Edit this article
Getting data into SAS
Purdue Engineering Computer Network
If you have an ASCII file containing your data, you can easily read it into a SAS dataset. SAS will read your data no matter how it looks in the file, but in the simplest case, data is either in columns or space separated. For example, it could look like this:
If you have an ASCII file containing your data, you can easily read it into a SAS dataset. SAS will read your data no matter how it looks in the file, but in the simplest case, data is either in columns or space separated. For example, it could look like this:
1 2This type of data format is called "column input format"; you tell SAS how to read each variable by specifying the columns it occupies in the file. Missing values are notated by no value in the specified column.
1--------0---------0---- <= Column
Daffy Duck 5
Porky Pig 3
Road Runner 4
Hewey 3
Your data file could also look like this:
Daffy Duck 5This format is called "list input format"; SAS recognizes that a space separates your variables. In list input format:
Porky Pig 3
Road Runner 4
Hewey . 3
* Fields must be separated by at least one blankIf your data is in one of these two simple forms, it is very easy to write a SAS program to read it in. The SAS statement 'input' allows you to describe your data format to SAS. To read variables in list input format, simply name the variables on the input line, adding a $ for variables which are made up of characters instead of numbers. For example, this input statement would read our sample data:
* Fields must be in a specified order
* Missing values must be represented by a place holder such
as a period (.)
* Character values longer than 8 characters need to be
treated specially
* Data cannot be in special formats (e.g. dates)
input first $ last $ age;To read the same data in column input format, you need to specify the columns each variable occupies:
input first $ 1-10 last $ 12-20 age 24;To put it all together into a complete SAS step (A step is a series of SAS statements), add lines resembling the following:
data <name>;Where
infile '<pathname>';
input <input specification>;
run;
<pathname> is the UNIX pathname to your data fileA specific example would look like this:
<name> is an 8 character (or less) name for your dataset
internal to SAS. By default it will be a temporary
dataset.
<input specification> is the input line as above.
data tdata;If your data is not this simple, or you want further information, consult the following SAS documentation:
infile '/home/harbor/joeuser/sasdata';
input first $ 1-10 last $ 11-20 age 22;
run;
SAS Language and Procedures, Usage Version 6, First Edition
chapters 2-4
SAS Language, Reference Version 6, First Edition
INFILE statement pgs 377-389
INPUT statement pgs 393-422
Last Modified:
Dec 19, 2016 11:12 am US/Eastern
Created:
Jun 21, 2007 12:55 pm GMT-4
by
admin
JumpURL: