Download presentation
Presentation is loading. Please wait.
Published byFranklin Paul Modified over 9 years ago
1
Chapter 7 Debugging Techniques Xiaogang Su Department of Statistics University of Central Florida
2
Section 7.1 Using the Debug Option (Self-Study) Objectives Use the DEBUG option in the DATA statement to help identify logic problems.
3
Scenario You have taken a new position in the company. Your predecessor wrote some code that was not working at the time he left. You need to identify what the program code is currently doing and where the problem is. ? ? ?
4
Scenario - Current Results Obs EMP_COUNTRY bonus type category 1 USA 2500 Overpaid 10 2 USA 2700 Overpaid 10 3 USA 12000 Overpaid 10 4 USA 4200 Overpaid 10 5 USA 3100 Overpaid 10 6 USA 2900 Overpaid 10 7 CANADA 8500 Overpaid 10 8 USA 3400 Overpaid 10 9 USA 2900 Overpaid 10 10 USA 2700 Overpaid 10 11 USA 3300 Overpaid 10 12 USA 2200 Overpaid 10 13 USA 1900 Overpaid 10
5
Scenario - Expected Results Obs EMP_COUNTRY bonus type category 1 USA 2500 Overpaid 10 2 USA 2700 Overpaid 10 3 USA 12000 Overpaid 10 4 USA 4200 Overpaid 10 5 USA 3100 Overpaid 10 6 USA 2900 Overpaid 10 7 CANADA 8500 Overpaid 10 8 USA 3400 Overpaid 10 9 USA 2900 Overpaid 10 10 USA 2700 Overpaid 10 11 USA 3300 Underpaid 1 12 USA 2200 Underpaid 1 13 USA 1900 Overpaid 10
6
Syntax Errors versus Logic Errors A syntax error occurs when program statements do not conform to the rules of the SAS language. An error message is produced by SAS and written to the log. A logic error occurs when the program statements follow the rules, but the results are not correct.
7
Logic Errors A non-programming example of a logic error: Recipe for Garlic Bread Spread butter on bread and sprinkle garlic powder on the bread. Place the bread on a baking sheet. Place the baking sheet under the broiler for 10 minutes. Remove and enjoy! Recipe for Garlic Bread Spread butter on bread and sprinkle garlic powder on the bread. Place the bread on a baking sheet. Place the baking sheet under the broiler for 10 minutes. Remove and enjoy! Notice that there is no step about turning on the broiler. The instructions work, but do not result in a desired finished product.
8
The DEBUG Option The DEBUG option is an interactive interface to the DATA step during DATA step execution. This option is useful to determine which piece of code is executing which piece of code is not executing what the current value of a particular variable is whether a “watch” must be placed on particular variables to inform you when the value changes.
9
The DEBUG Option General form of the DEBUG option: DATA data-set-name / DEBUG;
10
DEBUG Commands When the DEBUG option is running, these commands are very useful.
11
11 DEBUG Commands Controlling Program Execution: GO: Starts or resumes execution of the DATA step JUMP: Restarts execution of a suspended program STEP: Executes statements one at a time in the active program
12
12 DEBUG Commands Controlling the Windows HELP: Displays information about DEBUG commands SWAP: Switches control between the Source window and the Log window
13
13 DEBUG Commands Manipulating DATA Step Variables CALCULATE: Evaluates a debugger expression and displays the result DESCRIBE: Displays the attributes of one or more variables EXAMINE: Displays the value of one or more variables SET: Assigns a new value to a specified variable
14
14 DEBUG Commands Manipulating Debugging Requests BREAK: Suspends program execution at an executable statement DELETE: Deletes breakpoints or the watch status of variables in the DATA step LIST: Displays all occurrences of the item that is listed in the argument SET: Controls whether the debugger displays a continuous record of the DATA step execution WATCH: Suspends execution when the value of a specified variable changes
15
15 DEBUG Commands Tailoring the Debugger ENTER : Executes statements one at a time QUIT : Terminates a debugger session
16
What the DEBUG Option Cannot Do The DEBUG option can help to identify where a problem may be, but it is the programmer’s responsibility to solve the problem.
17
The FIRSTOBS= and OBS= Options The FIRSTOBS= and OBS= data set options are useful for testing because they can restrict the number of observations read in from a SAS data set. The number specified on the FIRSTOBS= option indicates the first observation number to read and the number specified on the OBS= option indicates the last observation number to read. SET data-set-name(FIRSTOBS=n OBS=n);
18
Determining Logic Errors This demonstration illustrates using the DEBUG option to identify which pieces of code are or are not executing display the data values of selected variables watch the data values of selected variables change. Program: Chap7.sas
19
Section 7.2 Using the PUT Statement (Self Study) Objectives Use the PUT statement in the DATA step to help identify logic problems.
20
Scenario You have taken a new position in the company. Your predecessor wrote some code that was not working at the time he left. You need to identify what the program code is currently doing and where the problem is. ? ? ?
21
The PUT Statement By default the PUT statement writes information to the log. This is useful to determine which piece of code is executing which piece of code is not executing what the current value of a particular variable is what the current values of all variables are.
22
The PUT Statement General forms of the PUT statement: PUT 'text'; PUT variable-name=; PUT _ALL_;
23
What the PUT Statement Cannot Do The PUT statement can help identify where a problem may be, but it is the programmer’s responsibility to solve the problem.
24
Determining Logic Errors This demonstration illustrates running code that does not produce the intended results and using the PUT statement to identify which pieces of code are or are not executing display the data values of all variables display the data values of selected variables.
25
A way to debug File: Chap7.sas
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.