DATA Step Call Routines for Macros |
Type: | DATA step call routine |
Syntax | |
Details | |
Comparisons | |
Examples | |
Example 1: Executing a Macro Conditionally | |
Example 2: Passing DATA Step Values Into a Parameter List |
Syntax |
CALL EXECUTE (argument); |
can be one of the following:
a character string, enclosed in quotation marks. Argument within single quotation marks resolves during program execution. Argument within double quotation marks resolves while the DATA step is being constructed. For example, to invoke the macro SALES, you can use the following code:
call execute('%sales');
the name of a DATA step character variable whose value is a text expression or a SAS statement to be generated. Do not enclose the name of the DATA step variable in quotation marks. For example, to use the value of the DATA step variable FINDOBS, which contains a SAS statement or text expression, you can use the following code:
call execute(findobs);
a character expression that is resolved by the DATA step to a macro text expression or a SAS statement. For example, to generate a macro invocation whose parameter is the value of the variable MONTH, you use the following code:
call execute('%sales('||month||')');
Details |
If an EXECUTE routine argument is a macro invocation or resolves to one, the macro executes immediately. However, any SAS statements produced by the EXECUTE routine do not execute until after the step boundary has been passed.
Note: Because macro references execute immediately and SAS statements do not execute until after a step boundary, you cannot use CALL EXECUTE to invoke a macro that contains references for macro variables that are created by CALL SYMPUT in that macro. See Interfaces with the Macro Facility, for an example.
Comparisons |
Unlike other elements of the macro facility, a CALL EXECUTE statement is available regardless of the setting of the SAS system option MACRO|NOMACRO. In both cases, EXECUTE places the value of its argument in the program stack. However, when NOMACRO is set, any macro calls or macro functions in the argument are not resolved.
Examples |
The following DATA step uses CALL EXECUTE to execute a macro only if the DATA step writes at least one observation to the temporary data set.
%macro overdue; proc print data=late; title "Overdue Accounts As of &sysdate"; run; %mend overdue; data late; set sasuser.billed end=final; if datedue<=today()-30 then do; n+1; output; end; if final and n then call execute('%overdue'); run;
CALL EXECUTE passes the value of the DATE variable in the DATES data set to macro REPT for its DAT parameter, the value of the VAR1 variable in the REPTDATA data set for its A parameter, and REPTDATA as the value of its DSN parameter. After the DATA _NULL_ step finishes, three PROC GCHART statements are submitted, one for each of the three dates in the DATES data set.
data dates; input date $; datalines; 10nov97 11nov97 12nov97 ; data reptdata; input date $ var1 var2; datalines; 10nov97 25 10 10nov97 50 11 11nov97 23 10 11nov97 30 29 12nov97 33 44 12nov97 75 86 ; %macro rept(dat,a,dsn); proc chart data=&dsn; title "Chart for &dat"; where(date="&dat"); vbar &a; run; %mend rept; data _null_; set dates; call execute('%rept('||date||','||'var1,reptdata)'); run;
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.