Lesson 2: Reading Data into a SAS Data Set - Part I

Overview Section

In order to be able to analyze our data, we need to be able to read it into a data set that our SAS software understands. In this lesson, we learn methods that will work in many situations to get your data read into a SAS data set. Keep in mind though that when reading data into a SAS data set, you always need to tell SAS three things:

  • where your data reside — Are they instream data, that is, embedded within your SAS program? Are they contained in a raw data file external to your SAS program? Or are they contained already in another SAS data set?
  • the format of the data — Are the data values arranged in neatly defined columns so that they can be read in using column input? Are the data values separated by at least one blank space so that they can be read in using list input? Do the data values contain special characters so that they must be read in using formatted input?
  • the kind of SAS data set that you want to create — Do you want to create a permanent SAS data set? Or do you want to create a temporary SAS data set?

In this lesson, we'll learn how to tackle all but two of the above situations. That is, we'll investigate how to read instream data, how to read data from an external raw data file, and how to read data from another SAS data set. We'll learn how to use column input to read in data values arranged in neatly defined columns. And, we'll learn how to create both temporary and permanent SAS data sets. In the next lesson, we'll investigate how to use formatted input and list input to read data into our SAS data sets.

Objectives

Upon completion of this lesson, you should be able to:

  • read stream data into SAS using a DATALINES or CARDS statement
  • read data into SAS from an external raw data file using an INFILE statement
  • use the SET statement to read data into a SAS data set from other SAS data sets
  • state how to create temporary SAS data sets
  • use the LIBNAME statement to create a new SAS data library
  • recall how to create permanent SAS data sets
  • read data into SAS using column input