Sample 24730: Use CALL EXECUTE to conditionally run sections of code
The sample code on the Full Code tab illustrates how to conditionally run procedures stored in macros based on the values of a variable.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data one;
do x=1 to 5;
output;
end;
run;
/* Create three macros containing the procedure code to execute depending on */
/* the value of the variable in the data set */
%macro print;
proc print data=one;
run;
%mend;
%macro means;
proc means data=one;
run;
%mend;
%macro freq;
proc freq data=one;
run;
%mend;
data _null_;
set one;
if x=1 then call execute('%print');
if x=3 then call execute('%means');
if x=5 then call execute('%freq');
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The results are PROC PRINT, PROC MEANS & PROC FREQ output from data set ONE
Obs x
1 1
2 2
3 3
4 4
5 5
The MEANS Procedure
Analysis Variable : x
N Mean Std Dev Minimum Maximum
-----------------------------------------------------------------
5 3.0000000 1.5811388 1.0000000 5.0000000
-----------------------------------------------------------------
The FREQ Procedure
Cumulative Cumulative
x Frequency Percent Frequency Percent
-------------------------------------------------------
1 1 20.00 1 20.00
2 1 20.00 2 40.00
3 1 20.00 3 60.00
4 1 20.00 4 80.00
5 1 20.00 5 100.00
Conditionally run procedures stored in macros based on the values of a variable.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> CALL routines
|
Date Modified: | 2005-12-08 11:34:27 |
Date Created: | 2004-09-30 14:09:08 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |