• define the variables and indicate whether they are character or numeric
• specify the location of the raw data
Telling SAS How to Read the Data: Styles of Input
SAS provides many tools for reading raw data into a SAS data set. These tools include
three basic input styles as well as various format modifiers and pointer controls.
List input is used when each field in the raw data is separated by at least one space and
does not contain embedded spaces. The INPUT statement simply contains a list of the
variable names. List input, however, places numerous restrictions on your data. These
restrictions are discussed in detail in Chapter 4, “Starting with Raw Data: The Basics,”
on page 51. The following example shows list input. Note that there is at least one
blank space between each data value.
data scores;
input Name $ Test_1 Test_2 Test_3;
datalines;
Bill 187 97 103
Carlos 156 76 74
Monique 99 102 129
;
Column input enables you to read the same data if it is located in fixed columns:
data scores;
input Name $ 1-7 Test_1 9-11 Test_2 13-15 Test_3 17-19;
datalines;
Bill 187 97 103
Carlos 156 76 74
Monique 99 102 129
;
Formatted input enables you to supply special instructions in the INPUT statement for
reading data. For example, to read numeric data that contains special symbols, you need
to supply SAS with special instructions so that it can read the data correctly. These
instructions, called informats, are discussed in more detail in Chapter 4, “Starting with
Raw Data: The Basics,” on page 51. In the INPUT statement, you can specify an
informat to be used to read a data value, as in the example that follows:
data total_sales;
input Date mmddyy10. +2 Amount comma5.;
datalines;
09/05/2013 1,382
10/19/2013 1,235
11/30/2013 2,391
;
In this example, the MMDDYY10. informat for the variable Date tells SAS to interpret
the raw data as a month, day, and year, ignoring the slashes. The COMMA5. informat
for the variable Amount tells SAS to interpret the raw data as a number, ignoring the
comma. The +2 is a pointer control that tells SAS where to look for the next item. For
more information about pointer controls, see Chapter 4, “Starting with Raw Data: The
Basics,” on page 51.
SAS also enables you to mix these styles of input as required by how values are arranged
in the data records. Chapter 4, “Starting with Raw Data: The Basics,” on page 51
Supplying Information to Create a SAS Data Set 41