Lesson 4: Assignment Statements and Numeric Functions

Overview Section

Once you've read your data into a SAS data set, surely you 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. You can change the data in one of two ways:

  1. You can use a basic assignment statement in which you add some information to all of the observations in the data set. Some assignment statements may take advantage of the numerous SAS functions that are available to make programming certain calculations easier (e.g., taking an average).
  2. Alternatively, you can use an if-then-else statement to add some information to some but not all of the observations. In this lesson, we will learn how to use assignment statements and numeric SAS functions to change your data. In the next lesson, we will learn how to use if-then-else statements to change a subset of your data.

Modifying your data may involve not only changing the values of a particular variable, but also the type of the variable. That is, you might need to change a character variable to a numeric variable. For that reason, we'll investigate how to use the INPUT function to convert character data values to numeric values. (We'll learn how to use the PUT function to convert numeric values to character values in Stat 481 when we study character functions in depth.)

Objectives

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

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

  • write a basic assignment statement involving a numeric variable
  • write an assignment statement that involves an arithmetic calculation
  • write an assignment statement that utilizes one of the many numeric SAS functions that are available
  • know how SAS handles missing values for various arithmetic calculations and functions
  • write an assignment statement involving nested functions
  • write a basic assignment statement involving a character variable
  • use the INPUT function to convert character data values to numeric values