on 12-19-2016 04:27 AM
To some, this Christmas tip might be old wine on new bottles, since this feature has actually been available for quite some time, but at least wasn't known to me until very recently. The reason I became aware of this, was this tiny new button in my Enterprise Guide window that caught my attention:
Thinking to myself, "what might this new button do...", I was pleasantly surprised to find out that this was a debugging tool I've known and loved from other programming tools I've used during my time at university. Starting to research further however, I quickly realized that this has actually been possible for a while, dating back at least to the old display manager days (which I know for a fact, hasn't seen any updates for quite a while).
data out / debug; set sashelp.class; run;
If you've ever come across the above "debug" option before, you might already be a debug-savvy, but regardless of knowing about this or not, I encourage you to read on! The new way of debugging is a lot more graphical, informative and user friendly, but with all the power of the well-known way. All in all, this just might be your new favorite tool for crushing those annoying bugs we all know and experience, buried deep within your complex data steps.
I'm of course speaking of the "new" Data Step Debugger (DSD), which is now available via a graphical user interface within your Enterprise Guide. All this new tool requires is the newest version (7.13) of Enterprise Guide. Clicking the aforementioned green button will display a data-step indicator for each data step in your code.
Clicking on the green "bug" for the data step you wish to debug, automatically brings the specified code into the debugger window. This window looks very simple on the surface, but has a few tricks up its sleeve.
Center stage, you of course have your SAS code, which you can walk through line by line. This is primarily controlled via the buttons up top. By placing a breakpoint on the lines of interest, you can make the execution pause in every iteration on this/these specific lines of code. This gives you the possibility to take a look at the current values of all the variables you have defined, and even calculate other values based on what you have in your table. This can be very helpful for figuring out what's wrong with the code!
If you're less sure exactly where the bug resides, pressing F10 will be of great value to you, or simply clicking "Step execution to next line".
On the right hand side, you have a complete overview of all your variables. Even the hidden variables you never get to see (unless you ask SAS nicely), like _ERROR_, first.x and end. Also, pay close attention to the "watch" tickbox, which when clicked, pauses the execution whenever the given variable is changed. This can be handy if your variable of interest is hiding in numerous lines of code, and you want to keep track of every change in value.
Speaking of change in variables, any value changes in the last executed line of code are indicated by red colored text for this variable.
In the lower left corner you have the Debug Console, which allows for typing in control commands, which is where most of the aforementioned tricks are hidden. I invite you to investigate these further on this support site, or clicking the looped square at the very right of the command line, for a cheat sheet of available commands.
For example by writing break 7 after 5, you can stop at the 7th line after 5 iterations of the data step, among many other avialable options.
A few things to note:
Enjoy the debugger, and your soon-to-be bug free code, and have a very merry christmas!
on 12-20-2016 09:39 AM
Great tip Allan,
If you want to see a video of this with the DATA STEP debugger in action in SAS Enterprise Guide, you can go to this video and jump 54 minutes forward into the video. Then you can see a 5 minutes demo of this.