SAS® Debugging   

Training Videos:

Don't Bug Me, I am Programming in SAS  



Being a good SAS programmer requires being a good SAS debugger.  

SAS Debugging involves first the identification of errors or issues and then methods to resolve the issue.  Errors could be as simple as syntax error which are easy to fix or as difficult as logic error which can only be fixed by knowing your data, such as min, max, relationships, code/uncoded, etc.. 

PROC FREQ for character variables and PROC MEANS for numeric variables help to describe the scope of the data.  Tools can be applied to scan SAS logs and send email alerts from batch jobs.

See also Data Validation, SAS Certification exam and System Options.  

  Three types of debugging issues to resolve:  

______________________________________________

Generally, if automatic SAS macro variables return a value other than 0, then there was an issue or error in the previous step.

1. Return of the Codes: SAS’®, Windows’®, and Yours, Mark Tabladillo

2. To Err is Human; to Debug, Divine, Roger Staum [ABORT]

______________________________________________

DATA Step Merge Rules

1. Don’t merge without a BY statement unless you know exactly what you are doing, and consider using the MERGENOBY=ERROR option to avoid doing so inadvertently.

2. Avoid performing a many-to-many merge (where multiple datasets have repeats of the same BY variable) unless you know exactly what you are doing. Use the SQL procedure when you need a Cartesian product.

3. Always set the length explicitly when merging on a BY variable with mismatched lengths, or avoid the situation in the first place.

4. Don’t merge with overlapping variables unless there is a specific reason you need to do so, and then only with full knowledge of how the merge actually works.

5. Avoid adding additional statements beyond those required for the merge: the DATA statement, the MERGE statement, the BY statement, possibly a subsetting IF statement, and of course the RUN statement. If this is too cumbersome, then at the very least, refrain from modifying the values of existing variables from an input dataset in a merge.

   Errors, Warnings and Notes Summary Sheet - Examples of Error types and PUT statements

  PDV Insights with Data Step Debugger - Examples of 

______________________________________________

Top Ten Common SAS Debugging Issues


1. ERROR: ARRAY SUBSCRIPT OUT OF RANGE AT LINE N AND COLUMN N.


2. ERROR 48-59: THE FORMAT $NAME WAS NOT FOUND OR COULD NOT BE LOADED. 


3. NOTE: 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. 


4. NOTE: INVALID ARGUMENT TO FUNCTION INPUT AT LINE N COLUMN N.  (One of the most common for inconsistent date values and formats)

Apply '??' before the format, ex. start=input(startdat, ?? date9.);
 
5. NOTE: MERGE STATEMENT HAS MORE THAN ONE DATA SET WITH REPEATS OF BY VALUES. 

 
6. NOTE: SAS WENT TO A NEW LINE WHEN INPUT STATEMENT REACHED PAST THE END OF A LINE. 

 
7. NOTE: INVALID DATA FOR VARIABLE-NAME AT LINE N

 
8. WARNING 32-169: THE QUOTED STRING CURRENTLY BEING PROCESSED HAS BECOME MORE THAN 262 CHARACTERS LONG. YOU MAY HAVE UNBALANCED QUOTATION MARKS.

 
9. WARNING: MULTIPLE LENGTHS WERE SPECIFIED FOR THE VARIABLE VARIABLE NAME BY INPUT DATA SET(S). THIS MAY CAUSE TRUNCATION OF DATA. 

10. ERROR: Where clause operator requires compatible variables.

Apply NOT MISSING() function since this is variable type independent, ex. where not missing(anvar);


Beginner Paper Errors, Warnings, and Notes (Oh My) A Practical Guide to Debugging SAS Programs, Susan J. Slaughter,Lora D. Delwiche

Data Cleanup Presentation and Tools [Course Notes]

The SAS Debugging Primer, Frank DiIorio

Animated Guide The SAS Data Step Debugger, Russ Lavery

SAS Log Error Checking Tool [SAS Tool, Scan]

 

SAS Utility ERRORLOG.SAS Sample Code to search through SAS Logs [Scan]

SAS Refernece Top 10 SAS Technical Support Call Issues, Calling Tips

Proc Report SAS Book Lookup of Errors and Warnings 

______________________________________________

1. Pruning the SASLOG – Digging into the Roots of NOTEs, WARNINGs, and ERRORs,
Andrew T. Kuligowski

2. The Automatic Detection of Problems in the SAS Log, MaryAnn Hope [Scan]

3. How to Use the Data Step Debugger, David Riba

4. Finding a Duplicate in a Haystack, Brett J. Peterson

5. The Problem With NODUPLICATES, Jack Hamilton

6. The Top 10 Head-Scratchers: SAS® Log Messages That Prompt
a Call to SAS Technical Support, Kim Wilson

7. Cutting the SAS Log Down to Size, Malachy Foley

8. SAS® Code Validation: L.E.T.O Method, Aaron Augustine

9. Figure Out Your Programming Logic Errors via DATA Step Debugger, Wuchen Zhao

10. Best Practices: PUT More Errors and Warnings in My Log, Please!, Mary F. O. Rosenbloom, Kirk Paul Lafler

11. Debugging 101, Peter Knapp  [Uninitialized Variable]

  • A. SYNTAX ERRORS
  • B. Execution-Time Errors
  • C. Invalid Data Error
  • D. LOGIC ERRORS

  • A. SYNTAX ERRORS
    • MISSING SEMICOLONS
    • THE PROGRAM WILL NOT STOP
    • MISSPELLED OR MISSING KEYWORDS
    • CODING STATEMENTS IN THE WRONG PLACE
    • QUICKLY CHECKING FOR SYNTAX ERRORS, OPTION OBS = 0;
  • B. Execution-Time Errors
    • UNINITIALIZED VARIABLES
    • Missing Values
    • Numeric and Character Conversions
  • C. Invalid Data Errors
    • Character Field Truncation
    • Illegal Mathematical Operations
    • BY GROUP PROCESSING
  • D. LOGIC ERRORS 

12. SAS Completion Codes to Make Complex Programs Run Smoothly, Heidi Markovitz [%SYSERR]

13. Missing Secrets, Robin Jones, Ian Whitlock

14. Tales from the Help Desk 3: More Solutions for Simple SAS® Mistakes, Bruce Gilsen

15. Tales from the Help Desk 4: Still More Solutions for Common SAS® Mistakes, Bruce Gilsen

16. Tales from the Help Desk 5: Yet More Solutions for Common SAS® Mistakes, Bruce Gilsen

17. More Tales from the Help Desk: Solutions for Common SAS ® Mistakes, Bruce Gilsen

18. It's Not a Bug, It's a Feature!!, Neil Howard, Linda Williams Pickle, James Pearson

19. ThE ART OF TESTING PROGRAMS WITH AN EMPHASIS ON LARGE FILES, Juliana Ma

20. The Dirty Dozen:  Twelve Common Programming Mistakes, Bob Virgile

21. Fifty Ways to Lose Your Data (and How to Avoid Them), Linda Jolley and Jane Stroupe

22. Strategies and Techniques for Debugging SAS® Program Errors and Warnings, Kirk Lafler

23. Defensive Programming, Avoiding the Big Mistakes, David Franklin

24. Importance of Warnings and Notes messages from SAS log, Jyotheeswara Naidu
Yellanki

25. What's That Note/Warning/Error Mean and How Do I Fix It?, Deb Cassidy

26. SAS Debugging 101, Kirk Lafler

27. Why Does SAS® Say That? What Common DATA Step and Macro Messages Are Trying to Tell You, Charley Mullin, Kevin Russell

28. The Most Useful New Parts of SAS® 9, Phil Mason [PUTLOG]

29. To Err is Human; to Debug, Divine, Roger Staum [%SYSERR]

30. Strategies for Error Handling and Program Control: Concepts, Thomas E. Billings

31. The Top 10 Head-Scratchers: SAS® Log Messages That Prompt a Call to SAS Technical Support, Kim Wilson

32. Emailing Automated Notification of Errors in a Batch SAS® Program, Julie Kilburn, Rebecca Ottesen [Macro]

33. You have got SASMAIL! Simple SAS® Macro for sending e-mails, Rajbir Chadha

34. You’ve Got E-Mail: Automatic Log Checking Via E-mail Notification, Aaron Augustine, Prasenjit Dutta

35. Cleaning up your SAS log: Note Messages, Jennifer Srivastava

36. Danger: MERGE Ahead! Warning: BY Variable with Multiple Lengths!, Bob Virgile

37. Why Does SAS® Say That? What Common DATA Step and Macro Messages Are Trying to Tell You, Charley Mullin and Kevin Russell

38. Check Please: An Automated Approach to Log Checking, Richann Watson [QC Macro]

39. Explaining Unexpected Log Messages and Output Results from DATA Step Code, Debbie Buck, Larry Stewart

40. Cleaning up your SAS® log: Note Messages, Jennifer Srivastava

41. Seeing Red: Tips for Debugging the SAS® Data Step, Michael Yee

42. Don't Despair, You Do Have An Option!, Wei Lin, Jiannan Kang

43. Fixing multiple length problems when merging many data sets [Macro]

44. Explaining Unexpected Log Messages and Output Results from DATA Step Code, Debbie Buck, Larry Stewart

45. Merge with Caution: How to Avoid Common Problems when Combining SAS Datasets, Joshua Horstman

       

46. HELP! - My MERGE Statement Has More Than One Data Set With Repeats of BY Values!, Andrew Kuligowski

47. More Tales from the Help Desk: Solutions for Simple SAS Mistake, Bruce Gilsen

48. To Error is Human: An Overview of Human Errors in SAS® Programming and How to Mitigate Them Nagadip Rao

49. LOG CHECKING: What to check and why? Sridhar Dodlapati, Kiran Kumar Karidi, Mahipal Vanam

50. Program Validation: Logging the Log, Adel Fahmy [ERROR: Unable to clear or re-assign the library]

51. Tips for Managing SAS® Work Libraries, Thomas Billings, Avinash Kalwani

52. A Simple Method for Colorizing Saved Log Files, Matthew Slaughter

Powered by Wild Apricot Membership Software