Lesson 7: Writing Programs That Work - Part I

Overview Section

Now that we know the basics of SAS, in this lesson, and the next, we'll spend some time shoring up our foundations with the intention of becoming more efficient SAS programmers. In order to write programs that work, we need to understand how SAS processes programs. So, we'll start by learning about its two processing phases — the compile phase and the execution phase. We'll look specifically at how SAS processes a data set when the DATA step reads in raw data. After discussing the process, we'll use the DATA step debugger to get a dynamic view of how SAS reads in raw data. In the process of doing that, you'll be introduced to the use of the DATA step debugger as a debugging tool. We'll also learn about the three different types of messages — errors, warnings, and notes — that SAS displays in the log window. Finally, we'll discuss four programming practices that will help us all become more efficient SAS programmers.

Objectives

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

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

  • describe how SAS processes programs from top-to-bottom and left-to-right
  • describe how during the compilation phase, SAS checks your program for syntax errors
  • describe how the descriptor portion of a SAS data set is created at the end of the compilation phase
  • describe how during the execution phase, the DATA step reads and processes the input data line by line
  • describe how the data portion of a SAS data set is created when the execution phase is complete
  • explain the use of an input buffer in the execution phase
  • explain the use of a program data vector in the execution phase
  • describe the purpose of the two automatic variables _N_ and _ERROR_
  • describe how the DATA step works like a loop
  • describe how (and when) SAS sets the value of each variable to missing at the beginning of each iteration of the DATA step
  • explain the order in which the variables are defined in the DATA step determines the order in which the variables appear in the output data set
  • describe how to use the SAS DATA step debugger to find execution-time errors
  • recognize the difference between error, warning, and note messages displayed in the log window
  • review the log window every time you execute a SAS program to see what errors, warnings, and notes your program caused SAS to display
  • write SAS programs that are easy to read
  • run the PRINT procedure to test each part of your SAS program to make sure your program is doing what you intended
  • describe how to use a PUT statement as a way to debug a program
  • test your programs with small data sets
  • test your programs with representative data