Debug SAS problems; don't repair drywall

3

Several years ago, my husband and I were remodeling our first house together.  We decided we wanted to have cable television upstairs.  Being young, foolish and lacking in disposable income, we decided to do it ourselves.  My husband said he would run the cable through the attic and drop it down the wall where we wanted the outlet.  He told me, “Put your ear against the wall and listen for the cable when I drop it.  Wherever you think the cable is, punch a hole in the drywall.”  Remember I said we were young and foolish, so of course I shrugged and said, “OK”.  About 15 holes later, I still had not located the cable.  The moral of the story is not to learn how to repair drywall (although that’s not a bad idea…).  The moral of the story is to learn how to diagnose your problems earlier.

When programming in SAS, you have several tools available to you to diagnose the problems with your data and programs.  Here are a few of my favorites:

  1. The PUTLOG DATA Step Statement: This is my favorite debugging tool.  The statement writes text and variable values to the SAS Log.  By placing the PUTLOG statement strategically in the DATA step at perceived trouble spots, you can determine when a variable value changes or a statement is executed.
  2. DATA statement DEBUG Option:  An interactive tool that enables you to use commands to determine the values of your variables at various points in your DATA step’s execution.  You can watch variables and print messages to the DEBUGGER LOG when certain variables change in value.
  3. PROC CONTENTS:   This should be one of your first stops in debugging to determine the type and formats associated with your variables.
  4. VIEWTABLE:  What’s not to love about this tool?  Accessible from the SAS Explorer, you can not only browse your SAS data sets interactively, but you can also edit, sort and subset.  No programming statements needed.  Brilliant.
  5. PROC FREQ:  A great way to determine if you have any invalid data values for categorical variables.  For example, GENDER should have the values of M or F only.  You can easily flag a stray G or N.

I should have used all of the tools available to me before knocking 14 more holes in my wall. If I did, maybe I would have found out there was a vertical divider in my wall that prevented the cable from dropping the extra 3 feet to where my outlet was supposed to be.  At least I learned how to repair drywall.

Learn more about debugging programs and validating data in our training courses SAS Programming 1: Essentials and SAS Programming 2: Data Manipulation Techniques.

Share

About Author

Susan Farmer

Hello! I'm Susan Farmer. In 1989, I began my career at SAS as an instructor. I started out teaching in the classroom in the Chicago training center. I had a stop along the way in Atlanta and now I teach Live Web classes from my living room in Phoenix. My specialty is the DATA step. I'm married and have two teenage daughters who would probably would not like me to claim them publicly. I hope to 'see' you in one of my classes!

3 Comments

  1. Nice short story Susan..The problems are almost the same whether it's a home repair project or a programming job. Identifying the root causes of problems at earlier stages is what a person should look for..

  2. The Proc Contents links takes me to the Base SAS 9.3 Procedures Guide.
    The ViewTable takes me to SAS 9.3 Language Reference.

    Easy enough to google both but just thought you'd want to know.

  3. Well, this was not exactly what I thought it would be! :) The "don't repair drywall" threw me off! Nice post, (which was a little above my head)!

    But if you are in Seattle, punch a bunch of holes in your walls for cable wire of any type, feel free to give me...aSeattle Sheetrocker, a call!

    :)

Back to Top