Usage Note 23134: Macro variables created with a CALL SYMPUT or SYMPUTX statement or an INTO clause do not resolve when invoked by the CALL EXECUTE routine
If a CALL EXECUTE routine argument is invoked via a macro invocation or resolves to one, the macro code executes immediately. However, any SAS® statements (such as CALL SYMPUTX and INTO) that are produced by a CALL EXECUTE routine do not execute until after a step boundary has been passed.
Because of this, the %NRSTR function has to be used in the CALL EXECUTE syntax. This enables you to reference the variables created by CALL SYMPUTX or INTO in the code generated by CALL EXECUTE. This workaround delays execution of the macro within the DATA step that contains the CALL EXECUTE.
The use of %NRSTR in the following example masks the call to the %TEST macro when the argument to the CALL EXECUTE routine is evaluated. This causes the %TEST macro invocation to be pushed onto the input stack. Prior to using %NRSTR, all the non-macro statements generated were pushed to the input stack. %NRSTR delays the execution of the %TEST macro until after the RUN statement for the DATA step containing the CALL EXECUTE statement.
Here is an example:
/*sample data set*/
data a;
value='Hello';
run;
/*sample macro*/
%macro test(val);
data _null_;
call symput('num',200);
run;
%if &num eq 200 %then %do;
proc print data=&val;
run;
%end;
%mend;
/*this will fail*/
data _null_;
temp='a';
call execute('%test('||temp||')');
run;
/*work-around*/
data _null_;
temp='a';
call execute('%nrstr(%test('||temp||'))');
run;
Starting with SAS
® 9.3 M2, the new DOSUBL function can be used instead of CALL EXECUTE. Here is an example:
data _null_;
temp='a';
rc=dosubl('%test('||temp||')');
run;
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Type: | Usage Note |
Priority: | low |
Topic: | SAS Reference ==> Macro
|
Date Modified: | 2013-09-04 16:13:10 |
Date Created: | 2003-03-19 10:24:33 |