DATA Step, Macro, Functions and more

Error handling in Macro facility

Occasional Contributor
Posts: 6

Error handling in Macro facility


Is there any way to start our exceution process from the error modified.
For example i have the following macro
%macro test;
data new;
set old;
proc contents data=now;
proc print data=old;

For example from the above %test macro i got an error at the contents step as i used now instead of new. In this case i will modify my code correctly to new then the code execution should start from proc contents only rather than from starting piece of code.

Is this possible ?

Trusted Advisor
Posts: 2,113

Re: Error handling in Macro facility

Possible?: yes.
Easy?: no.
Elegant?: no.

My past solution to that sort of problem involved defining all my check-points and then writing a DATA step that interrogated them and created a file with the adapted %MACRO code that was later %INCLUDEd. Effective, but not easy nor elegant.
Super Contributor
Super Contributor
Posts: 3,174

Re: Error handling in Macro facility

It is possible to add conditional SAS macro logic that tests expected conditions and only execute a particular code-piece when the condition is / is not met.

With this instance you can wrap code around the first DATA step to only execute it if the file being output does not already exist. You would use the EXIST(...) function as shown below:

* do your DATA step code here. ;

There are other techniques that can be exploited, such as using "gate" macro variable flags (or alternatively a temporary "gate" SAS file, instead), to set a value/condition as a SAS global MACRO variable, as your program progresses, and test for the file/variable existence and perform or skip SAS code pieces as needed.

Scott Barry
SBBWorks, Inc.

Suggested Google search argument, this topic / post:

conditional code execution
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation