1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.

Slides:



Advertisements
Similar presentations
Debugging ACL Scripts.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Debugging SAS Programs
VARIABLES AND DEBUGGING Beginning Programming. Assignment Statements  Used to hold values in a variable  Calculates a result and stores it in a variable.
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Chapter 17 Read Raw Data in Fixed Format using Formatted Input Objectives Distinguish between standard and nonstandard numeric data Read standard fixed-field.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
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.
Introduction to SAS Programming Christina L. Ughrin Statistical Software Consulting Some notes pulled from SAS Programming I: Essentials Training.
Programming Types of Testing.
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
What’s wrong NOW?! An introduction to debugging SAS programs for beginners Martha Cox Cancer Outcomes Research Program CDHA / Dalhousie.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Into to SAS ®. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Creating SAS® Data Sets
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
I OWA S TATE U NIVERSITY Department of Animal Science Writing Flexible Codes with the SAS Macro Facility (Chapter in the 7 Little SAS Book) Animal Science.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
Using Advanced INPUT Techniques Peter Cosette Dave Hall Amy Dunn-Ruiz Eric Lyon.
Math 3400 Computer Applications of Statistics Lecture 1 Introduction and SAS Overview.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Use the UPDATE statement to: –update a master dataset with new transactions (e.g. a bank account updated regularly with deposits and withdrawals…). Not.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
BMTRY 789 Lecture 2 SAS Syntax, entering raw data, etc. Lecturer: Annie N. Simpson, MSc. Readings – Chapters 1, 2, 12, & 13 Lab Problems 1.1, 1.2, 1.3,
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Chapter 16: Using Lookup Tables to Match Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
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.
1 Program Input Software Design Chapter 4. 2 You Will Want to Know... Prompting for and reading values into a program. Accessing data from a file. What.
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
A SAS User's Guide to Storage Management Allan Page Senior Marketing Analyst Canadian Tire Financial Services.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
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 18 Reading Free-Format Data. 2 Objectives Read free-format data not recognized in fixed fields. Read free-format data separated by non-blank delimiters,
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Chapter 21: Controlling Data Storage Space 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
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
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
Copyright 2009 The Little Engine That Could: Using EXCEL LIBNAME Engine Options to Enhance Data Transfers between SAS® and Microsoft® Excel Files William.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
Last week: We talked about: History of C Compiler for C programming
Testing and Debugging.
Chapter 2: Getting Data into SAS
Instructor: Raul Cruz-Cano
Chapter 2 – Getting Started
Conditions and Ifs BIS1523 – Lecture 8.
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
MATLAB Programs Chapter 6 Attaway MATLAB 5E.
CHAPTER 6 Testing and Debugging.
Presentation transcript:

1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009

2 Outline Fixing programs that don’t work Data step debugger SAS truncates a character variable SAS stops in the middle of the job SAS runs out of memory or Disk Space

3 1. Fixing programs that don’t work Read the SAS log SAS log has three types of messages about your program: errors, warnings, and notes. Start at the beginning when you read SAS log. Look for common mistakes first. Check your syntax. Searching for missing semicolon Most common errors in SAS. SAS usually give nonsense message when you miss semicolon. Use DATASTMTCHK system option EX: Options DATASTMTCHK=ALLKEYWORDS;

4 Note: Input statement reached past the end of the line If you see the note ‘SAS went to a new line when Input statement reached past the end of the line’, it usually means there is a problem. It means SAS was reading your data, it got to the end of the data line before it read values for all the variables in your Input statement. Possible causes: blank lines in your data file, use list input without a space between every value, some data lines are shorter than the rest and you are using column or formatted input. Use Proc Print or Viewtable to check your SAS data set.

5 Note: Lost Card A lost card means that SAS are expecting another line of data and did not find it. Printing the SAS data set as well as careful proofreading of the data file can be helpful in identifying problem areas.

6 Note: Invalid Data Common reasons for invalid data: Character values in a field that should be numeric Forgetting to specify that a variable is character Incorrect column specifications producing embedded spaces in numeric data List-style input with two periods in a row and no space in between Missing data not marked with a period for list-style input causing SAS to read the next data value. Special characters such as tab in numeric data Using the wrong informat such as MMDDYY instead of DDMMYY. Invalid dates (Sep. 31) read with a date informat.

7 Note: Numeric values have been converted to character When you accidentally mix numeric and character variables, SAS tries to fix your program by converting variables from numeric to character or vice versa. Converting variables Character to Numeric Newvar=Input (oldvar, informat); EX: newscore2=input(score2, 2.); Numeric to Character Newvar=PUT(oldvar, format); NewID=PUT(studentID, 3.);

8 Data step produces wrong results but no error message Use the Put and Putlog statements to debug. Put and Putlog statement: Putlog _ALL_; or Putlog variable-1= variable-2= … variable-n=; Ex: Data lowscore; infile ‘c:\class.dat’; Input name $ score1 score2 score3 Homework; Homework=Homework*2; averagescore=mean(score1+score2+score3+Homework); Putlog name= score1= score2= score3= Homework= averagescore=; If averagescore < 70; Run;

9 2. Data step debugger Starting the debugger (class.dat data set) Data lowscore/debug; infile ‘c:\class.dat’; Input name $ score1 score2 score3 Homework; Homework=Homework*2; averagescore=mean(score1+score2+score3+Homework); Putlog name= score1= score2= score3= Homework= averagescore=; If averagescore < 70; Run;

10 Data step debugger (cont’d) Executing debugger commands Command Results Execute one statement Step n Execute n statements Examine variable-list Prints the values of variables Set variable=expression Assigns a value to a specified variable for the current observation Go Finishes executing the Data Step Quit closes the debugger Ex: Examine _All_

11 Possible causes for invalid options and statements A misspelled key words A missing semicolon A Data step statement in a Proc step (or vice versa) A Run statement in the middle of a DATA or Proc Step The correct option with the wrong statement An unmatched quotation mark An unmatched comment.

12 Possible causes for “Variable not found” Misspelling a variable name Using a variable that was dropped at some earlier time Using the wrong data set Committing a logic error, such as using a variable before it is created.

13 3. SAS truncates a character variable The length of character variables are determined by the following methods: Input statement Ex: Input Food $; length: 8 Input Food $1-10; length: 10 Input Food $15.; length: 15 Assignment statement Ex: data summer; set temps; If Temperature > 100 then Status=‘Hot’; else Status=‘Cold’;

14 SAS truncates a character variable (cont’d) Length statement in Data step Ex: Length Status $4 Food $15; Attrib statement in Data step Ex: Attrib Status Length=$4 Label=‘Hot or Cold’; Data carsurvey; infile 'D:\Cars.dat'; input age sex income color$; length agegroup $6; if age < 20 then agegroup='Teen'; else if age < 65 then agegroup='Adult'; else agegroup='Senior'; proc print data=carsurvey; title 'Car color survey results'; run;

15 4. SAS stops in the middle of a job Possible causes: An unmatched quotation mark Submit ‘; run; An unmatched comment Submit */; run; No Run statement at the end of a program Submit run; Not sure what the problem is? Submit *’; *”; */; run; Out of time Batch system may have time limit, talk to systems programmer or other SAS user at your site. /* in the first column

16 5. SAS runs out of memory or disk space Memory and disk space Decrease the number of bytes needed to store the data to help decrease disk storage. Default is eight bytes for both numeric and character variables, can decrease it using input, length or attrib statement EX: length Answer $1; length Tigers 4; Subset your data or decrease the number of variables Clear the SAS log and output often. Compress SAS data set (might increase the size of your data set sometime) Ex: Data comzoo (Compress=YES); set zoo;