Macros ProgList and PutMvars to Show Calling Sequence and Parameters of %Include Routines

From sasCommunity
Jump to: navigation, search

sugi30.004: Journeyman's Tools: Macros ProgList and PutMvars to Show Calling Sequence and Parameters of %Include Routines

Author: Ronald_J._Fehd

TinyUrl: http://tinyurl.com/4raq59

Download the ProgList-and-PutMvars.zip file containing these two macros.

ProgList.sas

 /*      name: ProgList.sas
-------------: User Requirements:
purpose      : tool to trace calls of %include usage
description  : write note to log of %global mvar ProgList
-------------: Program Specifications:
program group: development and testing
program type : subroutine
SAS type     : macro procedure
note         : turned on by any of:
                  options nosource2;
               or invocation -oplist
               or invocation -verbose
input        : program name, action
process      : action eq INIT: assign ProgName to %global ProgList
               action eq SAVE: append ProgName to %global ProgList
                               write ProgList
               action eq EXIT: remove last item from %global ProgList
output       : note in log
note         : side effect: changes global mvar ProgList
note         : see also PutMvars
author       : RJF2macromaven@gmail.com
usage        : 
%ProgList(JobX,action=init);*in a job which calls routines;
options nosource2;
%Inc Project(RoutineA);
* - - - - RoutineA.sas - - - *;
%ProgList(RoutineA); *at top of called routine/subroutine;
*many other statements;
%ProgList(action=exit);*at end of called routine/subroutine;
****** ******** ........................ */
%MACRO proglist
         (Program
         ,Action  = Save /*init or exit */
         ,Pfx     = @@   /*prefix of log message */
         ,Sep_By  = :    /*separated by==infix   */
         ,Testing = 0 
         )
/des = "site utility: write note to log of program calls"
/* ** store source /* must have options mStored SASmStore=libref */
;/*change notes:
RJF2 03Nov07 written
RJF2 05Feb04 polishing for SUGI30
RJF2 2011Apr19 polishing for sas community wiki
******* ********* ............................. */
%global ProgList;*returned value: side effect;
%Let Testing = %eval(&Testing 
            or %sysfunc(getoption(source2)) eq NOSOURCE2
            or %sysfunc(getoption(oplist))  eq OPLIST
            or %sysfunc(getoption(verbose)) eq VERBOSE );
%if &Testing %then %do; 
    %Let  Action = %upcase(&Action.);
    %if   &Action. eq INIT %then %do;
          %if &Proglist ne %then %Put &Pfx.end &ProgList.;
          %Let ProgList = &Program.;
          %Put &Pfx.begin &ProgList.;
          %end;
    %else %if &Action. eq SAVE %then %do;
          %Let ProgList = &ProgList.&Sep_By.&Program.;
          %Put &Pfx.enter &ProgList.;
          %end;
    %else %if &Action. eq EXIT %then %do;
          %Put &Pfx.exit &ProgList.;
          %*remove last programName;
          %Let ProgList =%substr(&ProgList.,1
                ,%eval( %length(&ProgList.)
                - %index(%sysfunc(reverse(&ProgList.))
                ,&Sep_By.) ));
          %end;
    %end;
%mend ProgList;

PutMvars.sas

 /*      name: PutMvars.sas
-------------: User Requirements:
purpose      : tool to review parameters of includes
description  : write macro variable names and values to log
-------------: Program Specifications:
program group: development and testing
program type : subroutine
SAS type     : macro procedure
note         : uses SAS-supplied macro function cmpres
note         : turned on by any of:
               or invocation -verbose
input        : list of macro variables
process      : read each Mvar in list, put name and value
output       : to log
note         : see also ProgList
author       : RJF2macromaven@gmail.com
usage        :
%PutMvars(list = SysDate SysTime
         ,Msg = text);
%Let TestParms = 1;*alternate use: show mvar used to turn on;
%PutMvars(list = SysDate SysTime
,testing = &TestParms.);
****** ******** ........................ */
%MACRO putmvars
         (List    = /*of macro variables*/
         ,Msg     = parms: /*infix */
         ,Pfx     = @@     /*prefix of log message */
         ,Testing = 0      /*write to log? */
         )
/des = "site utility: write list of mvars + values to log"
/*store source /*must have options mStored SASmStore=libref*/
;/* change log ------------------------- **
RJF2 03Nov05 written
RJF2 05Feb04 polishing for SUGI30
RJF2 05Feb04 polishing for SUGI30
RJF2 2011Apr19 polishing for sas community wiki
****** ****** .......................... */
%local I     ; %Let I      = 1; %*loop index;
%local Item  ; %Let Item   =  ; %*Mvar Name to process;
%local nItems; %Let nItems = 1; %*items in list = N(spaces) +1;
%local Width ; %Let Width  = 1; %*max width of item;
%Let Testing = %eval(&Testing 
                     or %sysfunc(getoption(verbose)) eq VERBOSE );
%if &Testing. and &List ne %then %do; 
    %***how many Items in List?;
    %***change 2+ spaces to 1 space;
    %Let List = %cmpres(&List); 
    %*** nItems = number of spaces between items plus one;
    %Let nItems = %eval(1 + %length(&List)
                        - %length(%sysfunc(compress(&List))));
    %*** to align values in column <...> need:;
    %do I = 1 %to &nItems.; 
        %Let Width = %sysfunc(max(&Width
                         ,%length(%scan(&List.,&I.)))); 
        %end;
    %do I = 1 %to &nItems.; 
        %Let Item = %scan(&List.,&I.);
        %***string is 32 chars long: + 1 + 2 + 3 ;
        %***note: dot leader : 12345678901234567890123456789012;
    %Put &Pfx.&Msg. %substr(&Item.%str( ). . . . . . . . . . . . . . . *
                           ,1,&Width.) <&&&Item.>; 
        %end;
    %end; 
%mend PutMvars;

References

--Ronald_J._Fehd macro.maven == the radical programmer 16:34, 12 June 2012 (EDT)