When you run programs in SAS® 9.4M8 (TS1M8) and SAS® 9.4M9 (TS1M9), a Read Access Violation can occur when you place an open-code %IF statement immediately before a macro definition or macro invocation. The issue also occurs when you submit the program as a single block, although the same code runs successfully when executed step-by-step.
Here is an example of the problematic code:
%if 1 %then %do; %put Hello World!; %end;
%macro helloWorld;
%put Hello World!;
%mend helloWorld;
%helloWorld;
When you submit this code, you would expect the program to execute both the %IF statement and the macro call without errors. However, submitting the program instead triggers a Read Access Violation.
As a result, error messages similar to the following can occur:
The SAS task name is [OBJECT_EXECUTIVE]
ERROR: Read Access Violation OBJECT_EXECUTIVE
The SAS task name is [Submit]
ERROR: Read Access Violation Submit
The SAS 9.4M8 macro processor incorrectly handles open-code conditional logic when you place the open-code immediately before a macro definition or macro invocation. This parsing sequence can cause a memory access conflict, which produces a Read Access Violation.
To circumvent this issue, do either of the following:
Encapsulating the conditional logic prevents the parsing conflict.
Here is an example:
%macro helloWorld;
%if %eval(1) %then %do;
%put Hello World!;
%end;
%mend helloWorld;
%helloWorld;
Add a terminating step to ensure that SAS closes the open-code %IF block before reading the macro.
%if 1 %then %do; %put Hello World!; %end;
; * separation step;
%macro helloWorld;
%put Hello World!;
%mend helloWorld;
%helloWorld;