DATA Step, Macro, Functions and more

Error handling in Macro facility

Reply
Occasional Contributor
Posts: 6

Error handling in Macro facility

Hi,

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;
run;
proc contents data=now;
run;
proc print data=old;
run;
%mend;

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 ?

Thanks,
Jyothi
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:

%IF %SYSFUNC(EXIST())=0 %THEN %DO;
* do your DATA step code here. ;
%END;

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 site:sas.com
Ask a Question
Discussion stats
  • 2 replies
  • 182 views
  • 0 likes
  • 3 in conversation