Call Execute Parameterized Include

From sasCommunity
Jump to: navigation, search

Call Execute a Parameterized Include Subroutine

Using a Data Set as List of Parameters

List Processing Routine CallXinc: Calling Parameterized Include Programs Using a Data Set as List of Parameters

Author: Ronald_J._Fehd


Download the file containing Fehd-list-proc-routine-CallXinc.pdf.


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.


* routine name:;
* 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;
   _Stmnt    = "%Include &CxInclude.;";
   link    ExecStmnt;
*  housecleaning: SymDelete macro vars;
do I = 1 to dim(Mvar) -2;
   call   vname(Mvar(I)      ,_Name);
   _Stmnt = catx(' ','%symdel',_Name,';');
   link ExecStmnt;
return; ExecStmnt:
   if   Testing then putlog    _Stmnt=;
   call execute(cats('%nrstr(',_Stmnt,')'));
%Put Note2: CallXinc of &CxData. &CxInclude. ending;

Usage Demonstration


*filename SiteIncl '<directory-specification>';
*filename SiteIncl 'C:\SAS-site\includes';


* 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);


* name: PutGlobal;
%Put _global_;

Demo: Printing Outliers

This is a subroutine which prints a subset of any data set.

;/*    name:;
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

  1. task: prepare data set with data and where clause.
  2. 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. ;
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

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 


This is R&D for the book: A SAS(R) Companion: Journeymens_Tools

BibTeX entry for this page:

    booktitle={SAS Community Wiki},
    year     = 2008,
    author   ={Ronald J. Fehd},
    title    ={Call Execute a Parameterized Include},
    note     ={url for this article},
    url      ={}}

-- created by User:Rjf2 11:11, 12 September 2008 (EDT)

--Ronald_J._Fehd macro.maven == the radical programmer