Wednesday, January 13, 2010

Where, oh where, do my Macros live?

My last post provided a simple SAS program that could be packaged as a Stored Process and that could be used to run any macro. Lets generalize that program a bit - using macro variables.

But first lets talk a bit about a sample folder hierarchy for storing project code. I like to have a parent directory for projects/applications. As a consultant, typically I deal with projects and so I will have a structure like:
  • /Projects/ProjectA
  • /Projects/ProjectB
  • . . .
  • /Projects/Tools
where I like to use Tools for generic facilities that are not project or application specific (some people might want to refer to such things as Shared).

One simple way of pointing to the macro library is to include a statement like:

options sasautos=("/Projects/&Project/Macros"
                  "/Projects/Tools/Macros"
                  sasautos);


where the macro variable Project is defined as a parameter to the runMacro Stored Process. This code concatenates my Project specific autocall macro library, with my generic Tools macro and then the SAS supplied autocall macros.

So the complete Stored Process source is:

options sasautos=("/Projects/&Project/Macros"
                  "/Projects/Tools/Macros"
                  sasautos);
*ProcessBody;
%stpBegin;
%put NOTE: Execute macro &macroToRun..;
%&macroToRun
%stpEnd;

In my next post, I will address some packaging options so that I can reuse this same source for multiple projects.

And, BTW, did you notice I used the forward slash (/) in my file paths? That is because it works on both Unix and Windows, thus allowing the code to be migrated across environments more easily.

No comments:

Post a Comment