Example: air traffic controller

SUGI 25: How to Use the DATA Step Debugger

ABSTRACTAll SAS programmers, no matter if they arebeginners or experienced gurus, share the need todebug their programs. Many techniques have beensuggested over the years to solve the problem ofdebugging Data step logic. Until now SASprogrammers have never been able to interactivelywatch the Data step execute and debug their logicas it in Release of SAS, the Data StepDebugger is part of Base SAS software. It is aninteractive tool that allows the SAS user the abilityto watch and control DATA step Data Step Debugger can be used to: watch program logic execute examine variable values as they change repeat program statements jump to other sections of the DATA step modify DO loops interactively test for "dead" code give commands observe the results interactivelyThe Data Step Debugger is a very useful tool,whether you are a Beginning SAS Programmer or aSAS veteran.

DEBUGGER WINDOWS Once the Data Step Debugger has been invoked, an interactive environment is displayed. The Debugger environment consists of two windows -- …

Tags:

  Debugger

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of SUGI 25: How to Use the DATA Step Debugger

1 ABSTRACTAll SAS programmers, no matter if they arebeginners or experienced gurus, share the need todebug their programs. Many techniques have beensuggested over the years to solve the problem ofdebugging Data step logic. Until now SASprogrammers have never been able to interactivelywatch the Data step execute and debug their logicas it in Release of SAS, the Data StepDebugger is part of Base SAS software. It is aninteractive tool that allows the SAS user the abilityto watch and control DATA step Data Step Debugger can be used to: watch program logic execute examine variable values as they change repeat program statements jump to other sections of the DATA step modify DO loops interactively test for "dead" code give commands observe the results interactivelyThe Data Step Debugger is a very useful tool,whether you are a Beginning SAS Programmer or aSAS veteran.

2 This Tutorial will demonstrate how touse the Debugger . It will review the Debuggercommands, and demonstrate how they can be usedto improve the debugging process. While this is aBeginning Tutorial, the subject matter is appropriatefor all levels of SAS expertise if you have notpreviously been introduced to the Data Data Step Debugger was first introduced inRelease of the SAS System. It is shipped withReleases and of the SAS System and ispart of Base SAS Software. As its name implies,the Data Step Debugger is valid only for DATA steps and not for PROC steps. The Data Step Debugger is easy to use andsimplifies the task of debugging SAS Data It is intended to be used as an interactivedebugging tool, it can be used in either Interactiveor Batch mode. There are some very usefulreasons for adding Debugger commands to batchjobs.

3 Information about using the Debugger in batchmode is listed later in this THE DEBUGGERI nvoking the Data Step Debugger is as simple asadding a parameter to the DATA statement:DATA dsname / DEBUG ;When SAS encounters the DEBUG parameter onthe DATA statement, it changes the defaultbehavior for processing the Data step. Normally, SAS processes a Data step in two first pass compiles the Data step. This passperforms a syntax check, resolves any macrovalues, and converts the program text into aprogram which can be executed by the the Data step has compiled correctly,SAS then executes the Data step in a second , the user has no control over the executionof the code that has been compiled. The defaultbehavior is to execute the entire Data step programwith no external access. Historically, the onlymeans available to view or modify the execution ofa Data step has been with hard coded PUTstatements or conditional logic.

4 However, with theDEBUG parameter, SAS first compiles the Datastep and then enters DEBUG mode so the user caninteract with the execution of the Data step. InDEBUG mode, the user can view and control howSAS executes the Data step program to Use the Data Step DebuggerS. David Riba, JADE Tech, Inc., Clearwater, FLBeginning TutorialsDEBUGGER WINDOWSOnce the Data Step Debugger has been invoked, aninteractive environment is displayed. Th e Debuggerenvironment consists of two windows -- a SOURCE window and a LOG window. The SOURCE window displays the original Datastep source code. The currently executing line ishighlighted in the SOURCE window. The LOG window is similar to the Log window in theProgram Editor, with one major exception. TheDebugger LOG window contains an additionalcommand line. This command line i s for issuingcommands to the typical Data Step Debugger session might looklike this:The top window is the Debugger Log window.

5 Theresults from executing the Data step are displayedhere. The Debugger command line can be found atthe bottom of the Debugger Log window. TheDebugger command line follows the right arrow signat the bottom of the Log window > below the row bottom window is the SOURCE window. Here,the Data step code is displayed, and the current linebeing executed is highlighted. The line numbersdisplayed in the Debugger Log window are the sameas the line numbers displayed in the DebuggerSource window. The position and characteristics of each window canbe customized, the same as the SAS DisplayManager windows. Once a window has beenredefined, issue the WSAVE command topermanently store those definitions. Debugger EXPRESSIONSS ince the Data Step Debugger is different from theSAS Program Editor, it has different programmingrequirements than the Program Editor.

6 The commands that are issued from the Debuggercommand line must follow the following rules: There is a limited set of Debugger commands. Commands that are issued during a Debuggersession can include any valid SAS operator. SAS functions can not be used in a Debuggercommand. All commands must fit on one line. With oneexception (DO blocks), Debugger expressionscan not be continued on another line. Debugger commands can be assigned toFunction Keys. This saves considerable time,as well as lessening the opportunity for errors, iffrequently used commands are assigned toDebugger function keys. Macros can be issued from the Debuggercommand line. The RECALL command will recall Debuggercommands from the command stack. By default,the F4 key is assigned the value RECALL. Up to 20previous commands can be RECALLed from theDebugger command COMMANDST here are several categories of commands that canbe issued to the Data Step Debugger .

7 Thesecommands are issued on the Debugger CommandLine, which is at the bottom of the Debugger LOGwindow. These commands are also available fromthe Debugger Debugger commands can be grouped asfollows: Control Program Execution Manipulate Data Step Variables Manipulate Debugger Requests Tailor the Debugger Terminate the Debugger Control the Debugger WindowsEach of these groups will be discussed in turn onthe following pages. Beginning TutorialsDEBUGGER COMMANDS TO CONTROLPROGRAM EXECUTIONT here are three commands that control the order ofexecution of a Data Step. These commands are: GO JUMP STEP GOStarts or resumes execution of the Data a GO command is issued, executioncontinues until a BREAK point or WATCH variablechanges, or until the Data step terminates. Inaddition, GO can be modified by a line , GO 35 will continue to execute all programcode until line 35, and then will stop and await thenext Debugger can be shortened to the point to resume execution of the Datastep.

8 JUMP requires a valid line number or label forthe next program statement to execute. With theJUMP command, the normal order that a Data stepis processed can be modified under user of Data step code can be repeated, codecan be skipped, conditional logic blocks can beentered or terminated, etc. For example, to move directly to the labeled sectionHEADER: JUMP headerWhile it is possible to do so, it is unwise to JUMP into the middle of a DO loop or into a label that isthe target of a LINK - RETURN group. DirectlyJUMPing into either of these program groupsbypasses the normal controls and unexpectedresults can can be shortened to statements one at a time. STEP can takea numeric parameter, which will execute the next Xstatements ( STEP 4 will execute the next fourstatements). By default, the ENTER key stepsthrough the program sequentially, one line at a , this can be modified with the ENTER command, which will be reviewed later in this can be shortened to STDEBUGGER COMMANDS TO MANIPULATEDATA STEP VARIABLEST here are four commands that allow the user toexamine and change the values of Data stepvariables.

9 These commands are: CALCULATE DESCRIBE EXAMINE SETCALCULATEE valuates Debugger expressions and displays theresults. It is important to note that CALCULATE cannot evaluate an expression that uses a , calculate can be used with variablenames and numeric values. The results of thecalculation are displayed in the LOG window. CALCULATE var1 / var2 * 100 CALCULATE can be shortened to CAL. DESCRIBED isplays the attributes of a variable. DESCRIBE takes as a parameter the name of a variable or_ALL_. DESCRIBE will display the Name, Type,Length, Label, Informat, and Format for a an attribute is not currently defined for thevariable, it is not results are displayed in the LOG window. DESCRIBE _ALL_DESCRIBE can be shortened to DES or the current value of a variable or list ofvariables. Like DESCRIBE, EXAMINE takes as aparameter the name of a variable or _ALL_.

10 EXAMINE var1 var2 var3 .. varnIn addition, the format used to display the variablevalue can be changed. EXAMINE can be modifiedwith a valid example, to examine a date variable which doesnot have a format assigned (or to change theassigned format used for display purposes): EXAMINE dob results are displayed in the LOG can be shortened to E or EX. Beginning TutorialsSETA ssigns new values to a variable. SET takes theargument Variable = Expression. The variable to bechanged can also be used as part of the expression. SET value = value + 1 Unlike the default behavior exhibited during SASprogram execution, the expression to be evaluatedmust be the same type as the variable to beassigned. Thus, if the variable is character, theexpression can not be numeric. There is no impliedtype conversion in the immediately changes the value of the variable,but does not display any information in the can be shortened to COMMANDS TO MANIPULATEDEBUGGER REQUESTST here are five commands that allow the user tomanipulate the Debugger .


Related search queries