BookmarkSubscribeRSS Feed
MJyothi
Calcite | Level 5
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
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 881 views
  • 0 likes
  • 3 in conversation