Debugging SAS Programs

Slides:



Advertisements
Similar presentations
Debugging ACL Scripts.
Advertisements

Effecting Efficiency Effortlessly Daniel Carden, Quanticate.
compilers and interpreters
Introducing JavaScript
Types of selection structures
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
Getting Data into Your Program
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
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.
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
2440: 211 Interactive Web Programming JavaScript Fundamentals.
What’s wrong NOW?! An introduction to debugging SAS programs for beginners Martha Cox Cancer Outcomes Research Program CDHA / Dalhousie.
Debugging Introduction to Computing Science and Programming I.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
General Programming Introduction to Computing Science and Programming I.
Lesson 5 - Topics Formatting Output Working with Dates Reading: LSB:3:8-9; 4:1,5-7; 5:1-4.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
1 JavaScript in Context. Server-Side Programming.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
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.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
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.
Lecture 3 Topic - Descriptive Procedures Programs 3-4 LSB 4:1-4.4; 4:9:4:11; 8:1-8:5; 5:1-5.2.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
Here’s another problem (see section 2.13 on page 54). A file contains two different types of records (say A’s and B’s) and we only want to read in the.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Lesson 4 - Topics Creating new variables in the data step SAS Functions.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
1 Server versus Client-Side Programming Server-SideClient-Side.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
1 JavaScript in Context. Server-Side Programming.
Lesson 8 - Topics Creating SAS datasets from procedures Using ODS and data steps to make reports Using PROC RANK Programs in course notes LSB 4:11;5:3.
Lecture 4 Ways to get data into SAS Some practice programming
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
Chapter 9: Completing the Basics. In this chapter, you will learn about: – Exception handling – Exceptions and file checking – The string class – Character.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
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.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
1 Checking Data with the PRINT and FREQ Procedures.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
JavaScript: Conditionals contd.
Introduction to Computing Science and Programming I
Lesson 4 Descriptive Procedures
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Lesson 6 - Topics Formatting Output Working with Dates
Chapter 2 – Getting Started
How to Run a Java Program
Presentation transcript:

Debugging SAS Programs Finding and Correcting Errors

Checking the Log It is always a good idea to check the log file. Start at the beginning of the log file, and correct the first error. Sometimes one mistake can create many errors.

Errors, Warnings, and Notes There are three kinds of notifications that SAS inserts into log files: Errors, Warnings, and Notes. An Error indicates that there was a problem in the program and SAS could not execute the program. . A Warning indicates that there was a problem in the program, but SAS figured out how to continue. Notes can indicate that a program worked as planned or that a program worked differently. Some Notes are very important!

Backwards Illustrations When your SAS programs don’t work the way that you want, you’ll have to figure out what went wrong. In this lesson, errors will be introduced intentionally to see the results.

Missing Semicolons Missing semicolons are the most common mistake to make. From Program 4, if: DATA weight; INFILE 'C:\SAS_Files\tomhs.dat'; Is replaced with: DATA weight

One Missing Semicolon Produced: ERROR: No DATALINES or INFILE statement. ERROR: Extension for physical file name "C:\SAS_Files\tomhs.data" does not correspond to a valid member type. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.WEIGHT may be incomplete. When this step was stopped there were 0 observations and 8 variables. WARNING: The data set WORK.INFILE may be incomplete. When this step was stopped there

How to figure out what happened: The Error said that there wasn’t a DATALINES or INFILE statement, but you know that there was one. SAS must not have identified the INFILE statement as an INFILE statement. Checking the code shows that that SAS thought that the INFILE statement was part of the DATA statement because a semicolon was missing.

Another Missing Semicolon: From Program 4, if: PROC FREQ DATA=weight; TABLES sex clinic ; TITLE 'Frequency Distribution of Clinical Center and Gender'; Is replaced with: TABLES sex clinic

The Missing Semicolon Produced: ------------------------------------------------------- 22 200 ERROR: Variable TITLE not found. ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, *, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 200-322: The symbol is not recognized and will be ignored.

How to figure out what happened: SAS says that the variable TITLE wasn’t found. You know that TITLE isn’t a variable. SAS must think that TITLE is part of a list of variables. There is no semicolon separating TITLE from the variables SEX and CLINIC!

Unbalanced Quotation Marks An Unbalanced quotation marks warning can indicate that a quotation mark is missing. From Program 5, if: DATA tdata; INFILE 'C:\SAS_Files\tomhs.data’; Is replaced with: INFILE 'C:\SAS_Files\tomhs.data;

One Missing Quotation Mark Produced: WARNING: The quoted string currently being processed has become more than 262 characters long. You may have unbalanced quotation marks. 861 ; 850 INFILE 'C:\SAS_Files\tomhs.data; ------------------------- 49 NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS release. Inserting white space between a quoted string and the succeeding identifier is recommended.

What if you Balance the Quotation and Run Again? You still get errors! SAS interprets your program as a continuation of the program it ran before. Since there is an unbalanced quote, your quotes are still unbalanced and you get the Note: NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS release. Inserting white space between a quoted string and the succeeding identifier is recommended.

The Fix: Another Unbalance Quote Run these two lines of code: ‘ RUN; Do this ONCE (so the unbalance quote becomes balanced). You program should run properly now (as long as it is error-free).

Another Fix This may be easier to understand: First, correct the unbalanced quote. Second, save your SAS program. Third, exit SAS. Fourth, reopen SAS and run your saved program.

Invalid Data If SAS is expecting a number, but gets text instead, you can get invalid data notes. From Program 5, if: @ 12 clinic $1. Is replaced with: @ 12 clinic 1.

One Missing $ Produced: NOTE: The infile 'C:\SAS_Files\tomhs.dat' is: File Name=C:\SAS_Files\tomhs.dat, RECFM=V,LRECL=256 NOTE: Invalid data for clinic in line 1 12-12. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---- 1 C03615 C 11/10/1987 5 51 1 1 06/26/1936 5 4 2 71.5 05/17/1988 11/25/ 80 1988 205.5 199.0 093 084 143 138 36 36 5 260 046 111 159 4.8 063 02213 45.6 9.3 46.4 00471 00711 03611 01906 0.0 00 1 238 1 1 1 2 1 1 1 1 1 1 ptid=C03615 clinic=. group=5 sex=1 educ=4 evsmoke=2 alcbl=0 sebl_1=1 sebl_6=1 _ERROR_=1 _N_=1

Mixing up PROCs Different PROCs have different options. From Program 5, if: PROC FREQ DATA=tdata; TABLES clinic group sex educ sebl_1 sebl_6; Is replaced with: VAR clinic group sex educ sebl_1 sebl_6;

Using the Wrong Syntax Produced: 1015 PROC FREQ DATA=tdata; 1016 VAR clinic group sex educ sebl_1 sebl_6; --- 180 ERROR 180-322: Statement is not valid or it is used out of proper order. Note: Similar errors can be produced by missing semicolons

Misspelled Variable in a PROC From Progam 4, if: PROC FREQ DATA=weight; TABLES sex clinic ; Is replaced with: TABLES sex clinc ; You get: ERROR: Variable CLINC not found.

Uninitialized Variables From Program 4, if: bmi = (weight*703.0768)/(height*height); Is replaced with: bmi = (wieght*703.0768)/(height*height); You get: NOTE: Variable wieght is uninitialized.

What’s an Uninitialized Variable? An uninitialized variable is a variable that SAS considers to be nonexistent. This usually occurs when a variable name on the RHS of an equation is misspelled. In the example, the error was caused by a misspelling—SAS had no variable called wieght.

Forgetting the RUN Statement If you forget the RUN statement at the end of you program, SAS will not run (on PC) You won’t get any output. You may not get any errors or warnings. Fix: Run a single RUN; statement.

Catching Errors as You Write: You don’t have to write an entire program, then run the whole thing. Try writing your programs in stages. Write part and run it. If your program works, write the next part, and run it. If your program produced errors or warnings, it must have been from the last part that you wrote.

Multipart Programs If you are writing a program in stages, you may have multiple procedures. Running the same procedures over and over produces a lot of output and log files to check. Once you get a procedure to work, you can enclose it in a comment (/* . . . */) while you work on other procedures. Just remove the comment when you’ve finished the whole program.

Example: DATA weight; INFILE 'C:\SAS_Files\tomhs.dat'; INPUT @1 ptid $10. @12 clinic $1. @27 age 2. @30 sex 1. @58 height 4.1 @85 weight 5.1 @140 cholbl; bmi = (weight*703.0768)/(height*height); RUN; /* PROC FREQ DATA=weight; TABLES sex clinic ; TITLE 'Frequency Distribution of Clinical Center and Gender'; */ TABLES clinic/ NOCUM ; TITLE 'Frequency Distribution of Clinical Center '; TITLE2 '(No Cumulative Percentages) '; *Now SAS will only perform the second PROC FREQ;

Checking On Your Data Sets Sometimes your data steps don’t work the way you want, but there aren’t any clear indications of problems from the log file. You can insert a PROC PRINT to see your data: PROC PRINT DATA=mydata; RUN; Then, when you’re sure that your data is OK, you can either delete the PROC PRINT or convert it into a comment: *PROC PRINT DATA=mydata; *RUN;