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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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