Lesson 13: Reading SAS Data Sets

Printer-friendly versionPrinter-friendly version


We'll start this course off investigating something that you already know how to do well, namely reading SAS data sets. Well, that's not quite true — this lesson actually concerns a bit more than that. We will first review how to read data already contained in one SAS data set into another SAS data set. But then we'll explore the many ways in which a SAS data set can be modified. Some of the ways we will have seen before, such as changing a variable's attributes, while other ways will be new, such as using an accumulator variable to sum the contents of another variable. We'll then learn how to identify the first and last observations in a group, as well as the last observation in a data set. Then, we'll close out the lesson discussing the process SAS follows when reading in a SAS data set.

Learning objectives & outcomes

Upon completing this lesson, you should be able to do the following:

  • use a SET statement to read data into a SAS data set from another SAS data set
  • use an IF-THEN-DELETE statement to exclude observations from a SAS data set
  • use a subsetting IF statement to include observations in a SAS data set
  • use a DROP statement to reduce the number of variables in a SAS data set
  • use a LABEL, FORMAT, or LENGTH statement to change the attributes of a variable
  • create and use an accumulator variable
  • use a SELECT statement to assign values to a variable conditionally
  • use a SET and BY statement together in a DATA step in order to identify the first and last observations of a group and/or subgroup
  • use FIRST.variables and LAST.variables in order to create new variables, modify the structure of a data set, etc.
  • use the SET statement's END= option in order to identify the last observation in a SAS data set
  • describe how SAS processes a DATA step when it involves using a SET statement to read from one SAS data set into another SAS data set

Our "to do" list for this lesson

In order to complete the lesson you should:

  1. Read the lesson pages that follows.
  2. Type up your answers to the homework problems in a Word file named homework13_yourPSUloginid. If your PSU login id is xyz123, then name your file homework13_xyz123. Upload the file to the Lesson #13 Homework Dropbox.
  3. Post any questions or comments you have concerning the lesson's material to the Lesson #13 General Discussion Board.
  4. Take the Lesson #13 Mastery Quiz. Remember two things: i) You have 20 minutes to complete the quiz, and ii) as soon as you hit the "submit" button, your answers are submitted and graded, and the quiz becomes closed to you.