Help using Base SAS procedures

How to debug a sas program ?

Occasional Contributor
Posts: 13

How to debug a sas program ?

Without executing SAS dataset or any records can we check error in the sas program?

how can we debug sas program ?



Super User
Posts: 9,657

Re: How to debug a sas program ?

set option:

options obs=0;

data want;

   set have;



Xia Keshan

Message was edited by: xia keshan

Super Contributor
Posts: 254

Re: How to debug a sas program ?

SAS works with 2 steps(or PHASES).

In the first step known as COMPILATION PHASE, your code is parsed. If anything unknown to SAS in this step is detected and the Compilation stops the program throwing what it found in the LOG window. In this step, logical errors, mis-spelling of names of function names, missing of key words will be picked up. This is the step where many of your mistakes will be found. But still there remain other errors of coding in the code, such as wrong assignments, loop-evaluations etc. The second type of errors can be found by running the program(EXECUTION PHASE) statement by statement by the use of Data Step DEBUGGER. It will be placed after the first statement of your program like:

data want/debug;




Super User
Super User
Posts: 7,392

Re: How to debug a sas program ?

Well, until the code passes through the pre-processor you are not going to have full code.  This part of the process derives all your macro information and expands the code per macros.  Once that is done the full code is then sent to the compiler which parses the code into machine readable (or compiles it).  There is no checker as far as I am aware.  You can pre-check SQL code by using the noexec in the proc sql statement.  This checks the SQL but does not execute it.  I don't know of anything similar for SAS.  You can check for most issues just by looking at the colors in the Enhanced Editor (its why its different colors), for instance text strings not finished with same quote.  You could in theory build a text parse program to do checking, but why would you want to?  Your not building enterprise applications so the code is generally small and reasonably basic, and the compiler is already there to do the checking for you.  Just run it bit by bit interactively.  Also options like mprint symbolgen mlogic, and using %put statements help with debugging.

If you have a specific requirement, perhaps post an example?

Super User
Posts: 10,454

Re: How to debug a sas program ?

One simple thing if you are checking for syntax not logic in a datastep: Use RUN Cancel; which will not execute the code but the SAS compiler will run a syntax check.

Ask a Question
Discussion stats
  • 4 replies
  • 5 in conversation