CALL EXECUTE Routine

Resolves the argument, and issues the resolved value for execution at the next step boundary.
Type: DATA step call routine

Syntax

CALL EXECUTE (argument);

Required Argument

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. Execution of SAS statements generated by the execution of the macro will be delayed until after a step boundary. SAS macro statements, including macro variable references, will execute immediately.
Note: Because of the delay of the execution of the SAS statements until after a step boundary, references in SAS macro statements to macro variables created or updated by the SAS statements will not resolve properly.
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. For a workaround, see the following TIP.
Tip
The following example uses the %NRSTR macro quoting function to mask the macro statement. This function will delay the execution of macro statements until after a step boundary.
call execute('%nrstr(%sales('||month||'))');

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

Example 1: Executing a Macro Conditionally

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;

Example 2: Passing DATA Step Values into a Parameter List

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;
10nov11
11nov11
12nov11
;
data reptdata;
   input date $ var1 var2;
datalines;
10nov11 25 10
10nov11 50 11
11nov11 23 10
11nov11 30 29
12nov11 33 44
12nov11 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;