Published on :

Dynamic Execution with CALL EXECUTE

This code is also available in: Deutsch Español Français
This program demonstrates two methods for using the `CALL EXECUTE` routine within a `_NULL_` DATA step. The first method stores SAS© code (a `PROC PRINT` on `SASHELP.CLASS`) in a variable before execution. The second method directly passes the string containing the code to the routine. Both approaches generate and execute the SAS© code immediately after the DATA step compilation.
Data Analysis

Type : SASHELP


The data comes from the SASHELP.CLASS system table.

1 Code Block
DATA STEP
Explanation :
Defines a `myvar` variable containing the string of SAS code to be executed, then calls `CALL EXECUTE` to stack this code in the execution stream.
Copied!
1DATA _null_;
2 myvar='proc print data=sashelp.class; run;';
3 call execute(myvar);
4RUN;
2 Code Block
DATA STEP
Explanation :
Directly calls `CALL EXECUTE` with a literal string containing the SAS code (here, a PRINT procedure).
Copied!
1 
2DATA _null_;
3call execute('
4proc print
5data=sashelp.class;
6 
7run;
8');
9RUN;
10 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.