Lesson 5: If-Then-Else Statements

Overview Section

Again, once you've read your data into a SAS data set, you probably want to do something with it. A common thing to do is to change the original data in some way in an attempt to answer a research question of interest to you. In the last lesson, we learned how to use assignment statements (and functions) to add some information to all of the observations in the data set. In this lesson, we will learn how to use if-then-else statements to add some information to some but not all of the observations in your data set.

Objectives

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

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

  • follow the good programming practice of programming for missing values
  • write an if-then-else statement that involves any of the comparison operators
  • write a series of mutually exclusive conditions for use in an (efficient) if-then-else statement
  • use the AND and OR operators to combine conditions for use in an if-then-else statement
  • write an if-then-else statement that compares character values efficiently and accurately