Call Execute Parameterized Include
From sasCommunity
Call Execute a Parameterized Include Subroutine
Using a Data Set as List of Parameters
TinyUrl: http://tinyurl.com/4rf2a7
Download the CallXinc.zip file containing Fehd-list-proc-routine-CallXinc.pdf.
Quote:
- Any sufficiently advanced technology is indistinguishable from magic.
- Arthur Clarke
- http://en.wikipedia.org/wiki/Clarke's_three_laws
Description: list processing routine which calls a subroutine using values of character columns as values of macro variable assignment statements. Subroutine called references global macro variables
Purpose: list processing
Demonstration of concept:
%Let Parm1 = value1; %Let Parm2 = value2; %Include FileRef(SubRoutine);
CallXinc reads each row of parameter data set, allocates global macro variables for each character variable, and calls -- %Includes -- the subroutine.
Contents |
CallXinc
* routine name: CallXinc.sas;
* description : Call Execute parameterized Include program;
* purpose : list processing of routine or subroutine;
* note : This is a Derivative Work of CallExecInclude;
* parameters : option source2;
* input : CxData;
* CxInclude;
* process : make mvar of each variable;
* call named Include(s);
* output : from subroutines;
* usage ;
%*Let CxData = sashelp.class;
%*Let CxInclude = SiteIncl(PutGlobal);
%*Include SiteIncl(CallXinc);
* Notes : RJF2 4/23/2008 made routine from Call Execute Suite;
DATA _Null_;
if 0 then set &CxData.;
attrib _Stmnt length = $132
_Name length = $ 32;
array Mvar(*) _character_;
retain Testing %eval(0 or %sysfunc(getoption(Source2)) eq SOURCE2);
do until(EndoFile);
set &CxData. end = EndoFile;
* make statement: *let Mvar = value;
do I = 1 to dim(Mvar) -2;
call vname(Mvar(I) ,_Name);
_Stmnt = catx(' ','%let',_Name,'='
,Mvar(I) ,';');
link ExecStmnt;
end;
_Stmnt = "%Include &CxInclude.;";
link ExecStmnt;
end;
* housecleaning: SymDelete macro vars;
do I = 1 to dim(Mvar) -2;
call vname(Mvar(I) ,_Name);
_Stmnt = catx(' ','%symdel',_Name,';');
link ExecStmnt;
end;
stop;
return; ExecStmnt:
if Testing then putlog _Stmnt=;
call execute(cats('%nrstr(',_Stmnt,')'));
return;
run;
run;
%Put Note2: CallXinc of &CxData. &CxInclude. ending;
Usage Demonstration
autoexec
*filename SiteIncl '<directory-specification>'; *filename SiteIncl 'C:\SAS-site\includes';
CallXinc-Test
* name: CallXinc-Test; %Let CxData = sashelp.class; %Let CxInclude = Project(PutGlobal); %Include SiteIncl(CallXInc); %Let CxData = sashelp.class(where = (Sex = 'F')); %Let CxInclude = Project(PutGlobal); %Include SiteIncl(CallXInc);
PutGlobal
* name: PutGlobal; %Put _global_;
Demo: Printing Outliers
This is a subroutine which prints a subset of any data set.
;/* name: SEsPrnt.sas;
description: show subset;
purpose : data review;
input : parameters: Data Where;
process : print;
output : listing;
****** */
PROC Print data = &Data.
(where = (&Where.));
title3 "&Data. &Where.";
run; title3;
%Put Note2: SEsPrnt of &Data. &Where. ending;
See Art Carpenter: using data set as list of criteria
- task: prepare data set with data and where clause.
- task: for each subset print the subset
Title2 make-data-where;
* a SmryEachVar data review module;
%Let Out_Lib = Library;
%Let Out_Lib = Work;
DATA &Out_Lib..Data_Where;
attrib Data length = $42
Where length = $72;
infile cards truncover;
input @1 Data Where $72. ;
cards;
sashelp.class Sex eq 'F' and Weight Le 80
sashelp.class Sex eq 'M' and Height ge 70
;
PROC Print data = &SysLast.;
%Let CxData = &Out_Lib..Data_Where;
%Let CxInclude =Project(SEsPrnt);
%Include SiteIncl(CallXinc);
This is the listing.
The SmryEachVar Data Review Suite
make-data-where
Obs Data Where
1 sashelp.class Sex eq 'F' and Weight Le 80
2 sashelp.class Sex eq 'M' and Height ge 70
sashelp.class Sex eq 'F' and Weight Le 80
Obs Name Sex Age Height Weight
11 Joyce F 11 51.3 50.5
13 Louise F 12 56.3 77.0
sashelp.class Sex eq 'M' and Height ge 70
Obs Name Sex Age Height Weight
15 Philip M 16 72 150
References
- See also definition: Parameterized_include_file
- This routine is in the SmryEachVar v2 data review suite:
- and is included in the .zip of both
- Reading Job Logs
- Reading Rtrace Logs
- replacement for macro %if
- replacement for macro %do
- List Processing with Call Execute: Routine CallXinc for calling parameterized include program using a data set as list of parameters
- http://www.pharmasug.org/download/papers/AD02.pdf
- usage: Listing_Macros_in_SASautos
This is R&D for the book: A SAS(R) Companion: Journeymens_Tools
--macro maven == the radical programmer 11:11, 12 September 2008 (EDT)
BibTeX entry for this page:
@inproceedings{sas-wiki.callxinc,
booktitle={SAS Community Wiki},
year = 2008,
author ={Ronald J. Fehd},
title ={Call Execute a Parameterized Include},
note ={url for this article},
url ={http://www.sascommunity.org/wiki/Call_Execute_Parameterized_Include}}
