Execute a macro with the value from a dataset observation
%******************************************************************************; %** http://www.info-net.nl **; %******************************************************************************; %* Topic : SAS Macro *; %* Program : Execute a macro with the value from a dataset observation *; %* Author : Raymond Ebben *; %* Location : http://www.info-net.nl/index/sas-coding/sas-macro *; %* Date : March 2006 *; %* Version : 1.0 *; %* Description : This program illustrates how to call a macro with the *; %* content of a dataset as values *; %******************************************************************************; %* In datasets : SAShelp.class *; %* In macrovars : None *; %* In files : None *; %* Out datasets : None *; %* Out macrovars : None *; %* Out files : None *; %******************************************************************************; %** Version control **; %******************************************************************************; %* Mod * Ver. * Date * Description *; %******************************************************************************; %******************************************************************************; %******************************************************************************; %* Create a macro which processes the values form the dataset *; %******************************************************************************; %macro DatasetContents(Studentname=); %****************************************************************************; %* Start macro processing as anexmple the value of studentname is checked *; %****************************************************************************; %if &Studentname eq Alfred %then %put Student Alfred located; %else %put Student Alfred not located; /* ....... */ %mend DatasetContents; %******************************************************************************; %* The following call execute statement will execute the specified macro for *; %* each observation in the dataset *; %******************************************************************************; data _null_; set sashelp.class; call execute('%DatasetContents(Studentname='||left(trim(name))||');'); data='%DatasetContents(Studentname='||left(trim(name))||');'; put data=; run; %******************************************************************************; %* The call execute statement will write code that will be executed AFTER *; %* the dataset is executed *; %* In principle it generates the following code: *; %* %DatasetContents(Studentname=Alfred); *; %* %DatasetContents(Studentname=Alice); *; %* %DatasetContents(Studentname=Barbara); *; %* ...etc. *; %******************************************************************************;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
© 2010 Raymond Ebben, expert SAS consultant and programmer, Netherlands All Rights Reserved.