BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

Debugging SAS Programs
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Chapter Chapter 4. Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times.
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
Question 1 Which is an example of a rational expression? A. ½ B. 5 C. D. None of the above.
Chapter 7: Introduction to Debugging TECH Prof. Jeff Cheng.
Objectives In this chapter, you will learn about:
Debugging Introduction to Computing Science and Programming I.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Welcome to the Exciting World of ! Lessons to familiarize yourself with.
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
An Introduction to Textual Programming
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
General Programming Introduction to Computing Science and Programming I.
Enrolment Services – Class Scheduling Fall 2014 Course Combinations.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Using Advanced INPUT Techniques Peter Cosette Dave Hall Amy Dunn-Ruiz Eric Lyon.
Program Development Life Cycle (PDLC)
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
BMTRY 789 Introduction to SAS Programming Lecturer: Annie N. Simpson, MSc.
Checking data GCSE ICT.
Checking data Chapter 7 Prepared by:Sir Mazhar Javed.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Introduction to Exception Handling and Defensive Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
C Hints and Tips The preprocessor and other fun toys.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
When I want to work with SQL, I start off as if I am doing a regular query.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
TCU CoSc Introduction to Programming (with Java) Java Language Overview.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes.
Lecture 7 Conditional Scripting and Importing/Exporting.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
The Debugging Process Syntax Errors CPS120 Introduction to Computer Science Lecture 4.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Introduction to Exceptions in Java CS201, SW Development Methods.
Introduction to Computing Science and Programming I
BIT116: Scripting Lecture 06
What to do when a test fails
Computer Programming I
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Conditions and Ifs BIS1523 – Lecture 8.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
An Introduction to Debugging
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
How to Run a Java Program
Presentation transcript:

BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations

Summer 2009 BMTRY 789 Introduction to SAS Programming 2 Debugging? “If debugging is the process of removing bugs, then programming must be the process of putting them in.” –From some strange, but insightful website

Summer 2009 BMTRY 789 Introduction to SAS Programming 3 Syntactic Errors vs. Logic Errors This lecture focuses only on syntax errors; however, it is also possible for SAS to calculate a new variable using syntactically correct code that results in inaccurate calculations, i.e. a logic error. For this reason, it is always wise to check values of a new variable against values of the original variable used in the calculation.

Summer 2009 BMTRY 789 Introduction to SAS Programming 4 Testing Test each part of your program separately before putting it all together Use Proc Print after your data step to check if your data is correct Use small data sets to initially test, or use portions of your data 1. Infile ‘Mydata.Dat’ OBS=100; 2. Infile ‘Mydata.Dat’ Firstobs=101 Obs=200; 3. Data mydata; Set olddata (Obs=50);

Summer 2009 BMTRY 789 Introduction to SAS Programming 5 Wrong results…but no error? This means that you have a logic problem not a syntax problem. SAS won’t catch these, you have to! To figure out exactly what is happening in the data step use a PUT statement. SAS will then write the data to the Log PUT _all_; (use this for all variables and their values) PUT varname= varname = ; (just the variables that you select will be printed along with their values. If you don’t put the = then the variable names will not be printed, only the values)

Summer 2009 BMTRY 789 Introduction to SAS Programming 6 READ THE LOG WINDOW!! I know that I spout this all of the time, and that is because too many people begin skipping this step and then can’t figure out why their program isn’t working If you have an ERROR message, look at that line as well as a few of the lines above it Don’t ignore Warnings and Notes in the log simply because your program seems to have run, they could indicate a serious error that just did not happen to be syntactically incorrect, in this case, check your logic or add some Proc Prints to understand what is going on inside your program

Summer 2009 BMTRY 789 Introduction to SAS Programming 7 Types of errors in the Log There are 3 main types of messages that SAS will generate in the log: 1) Notes 2) Errors 3) Warnings

Summer 2009 BMTRY 789 Introduction to SAS Programming 8 1. "NOTE" Notes are always generated in the log; they provide important information about the processing of the SAS program such as: number of observations and number of variables in a newly created data set. length of time taken by the processing (both real and cpu time). indications of certain types of programming errors.

Summer 2009 BMTRY 789 Introduction to SAS Programming 9 "NOTE"

Summer 2009 BMTRY 789 Introduction to SAS Programming 10 Note: Numeric Values Have Been Converted to Character When you accidentally mix numeric and character variable, SAS tries to fix your program by converting variables for you Don’t let SAS do this, if you need a conversion done, do it yourself using the PUT() or INPUT() function.

Summer 2009 BMTRY 789 Introduction to SAS Programming "ERROR" Error messages are the most obvious clue that something is wrong with the SAS program. Unlike Notes and Warnings, the program will not complete processing until the necessary changes have been made. Because one error can result in multiple error messages, fixing the first-occurring error will frequently clear up the remaining error messages.

Summer 2009 BMTRY 789 Introduction to SAS Programming 12 "ERROR"

Summer 2009 BMTRY 789 Introduction to SAS Programming "WARNING" Warnings are frequently indications of problems in how SAS processed the program (although not always, and it should be noted that SAS may not always stop processing the program). Warnings should always be investigated.

Summer 2009 BMTRY 789 Introduction to SAS Programming 14 "WARNING"

Summer 2009 BMTRY 789 Introduction to SAS Programming 15 Debugging: The Basics The better you can read and understand your program, the easier it is to find the problem(s). Put only one SAS statement on a line Use indentions to show the different parts of the program within DATA and PROC steps Use comment statements GENEROUSLY to document your code

Summer 2009 BMTRY 789 Introduction to SAS Programming 16 Know your colors Make sure that you are using the enhanced editor and know what code is generally what color (i.e. comments are green)

Summer 2009 BMTRY 789 Introduction to SAS Programming 17 Scroll Up Remember that your output and log windows are scrolled to the very bottom of the screen, scroll ALL the way up and check the whole thing. Look for common mistakes first (Semicolons and spelling errors!) Make sure you haven’t typed an ‘O’ where you want an ‘0’ or vice versa, this can cause SAS to think that your numeric or character variable should be change to the other variable type. SAS may do this automatically when you don’t want it done!

Summer 2009 BMTRY 789 Introduction to SAS Programming 18 What is wrong here? *Read the data file ToadJump.dat using a list input Data toads; Infile ‘c:MyRawData\ToadJump.dat’; Input ToadName$ Weight Jump1 Jump2 Jump3; Run;

Summer 2009 BMTRY 789 Introduction to SAS Programming 19 Here is the log window… ___________________________________________________________ *Read the data file ToadJump.dat using the list input Data toads; Infile ‘c:\MyRawData\ToadJump.dat’; ERROR : Statement is not valid or it is used out of proper order. Input ToadName$ Weight Jump1 Jump2 Jump3; ERROR : Statement is not valid or it is used out of proper order. Run; __________________________________________________________

Summer 2009 BMTRY 789 Introduction to SAS Programming 20 DATASTMTCHK System Option Can make some mistakes easier to find, like the missing semicolon in the previous slide. This prevents you from accidentally overwriting an existing data set just because you forget a semicolon. You can make ALL SAS keywords invalid SAS data set names by setting this option to ALLKEYWORDS Options DataStmtChk=Allkeywords;

Summer 2009 BMTRY 789 Introduction to SAS Programming 21 Log window with this option OPTIONS DATASTMTCHK=ALLKEYWORDS; *Read the data file ToadJump.dat using the list input Data toads Infile ‘c:\MyRawData\ToadJump.dat’; ERROR : Infile is not allowed in the DATA statement when option DATASTMTCHK=ALLKEYWORDS. Check for a missing semicolon in the DATA statement, or use DATASTMTCHK=NONE. Input ToadName$ Weight Jump1 Jump2 Jump3; Run; ERROR: Memtype field is invalid

Summer 2009 BMTRY 789 Introduction to SAS Programming 22 What’s wrong?

Summer 2009 BMTRY 789 Introduction to SAS Programming 23 Long quote warning A very common Warning is the one illustrated in the previous slide, saying that a quoted string has become extremely long. Most frequently, the problem is a quote being inadvertently left out. In this case, adding the missing quote (i.e., '820 '<=diag02<='82099') will fix the problem and remove the Error messages showing up in the rest of the program.

Summer 2009 BMTRY 789 Introduction to SAS Programming 24 What else was wrong?

Summer 2009 BMTRY 789 Introduction to SAS Programming 25 SAS is still running… This will not, however, fix an associated problem. A most important caveat when receiving this type of log message is to also check the message above the menu on the Log window. If it says, as in this example, "DATA STEP running", then steps must be taken to stop the program from running. Even though SAS will continue to process other programs, results of such programs may be inaccurate, without any indication of syntax problems showing up in the log.

Summer 2009 BMTRY 789 Introduction to SAS Programming 26 SAS is still running… Several suggestions to stop the program are: Submit the following line: '; run; Submit the following line: *))%*'''))*/; If all else fails, exit SAS entirely (making sure that the revised program has been saved) and re-start it again.

Summer 2009 BMTRY 789 Introduction to SAS Programming 27 SAS stops in the middle of a job You have an unmatched quote or comment You have no RUN statement at the end of your program As in the slide previous you may have to submit this in order to stop it from being stuck: *’; *”; */; Run;