The following output, produced with the PRINT procedure, displays the data set that has
just been created.
Figure 3.14 PROC PRINT Output of the WEIGHT_CLUB Data Set
Supplying Information to Create a SAS Data Set
Overview of Creating a SAS Data Set
You supply SAS with specific information for reading raw data so that you can create a
SAS data set from the raw data. You can use the data set for further processing, data
analysis, or report writing. To process raw data in a DATA step, you must:
use an INPUT statement to tell SAS how to read the data
40 Chapter 3 Introduction to DATA Step Processing
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

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.