Sometimes you will not want to copy all of my macros and place them in
a library where other people can use them. Instead you may want a minimum
set of these macros such that your solution, which uses my macros, uses
only those macros that will be needed in the process. This page tells you
how to do this.
Windows and Cygwin
The system commands and scripting capabilities of Windows PCs are almost
non-existent even though the operating system does much the same as most
other operating systems. On Linux, the commands and scripting capabilities
are excellent and yet Linux does the same sort of thing that Windows does.
In an ideal world, you would be able to use Linux commands and scripting
capabilities on Windows -- and indeed that is possible using a Linux emulator
such as Cygwin that runs on Windows PCs and emulates the Linux environment.
The description I will give you tells you how to copy a minimum set of
macros using Linux commands. If you have a Windows PC then you will need
to install the Cygwin Linux emulator on your PC. How to do this is explained
elsewhere on this web site. If you don't want to install Cygwin then you
can still do things manually and this will be explained. Installing Cygwin
on your PC should never bother you. Your PC does not turn into a Linux
box if you install Cygwin on it. It will still use Windows services to
do everything. All Cygwin does is emulate Linux using Windows services.
Cygwin is a Linux emulator. It is not Linux itself. If your platform
is Linux or Unix then you have no problem. If it is Windows then somebody
ought to give serious thought to installing Cygwin on it so people have
a good set of tools to use. If you don't have Cygwin on your PC then I
can't give you much help except to let you know how to identify the macros
you need to copy so that you can do this manually. They are identified
in your sas log by lines that start with "MACRO CALLED:" as will be explained
in the next section.
Copying a list of all the needed macros
All my macros put out a message saying what macro has been called. So long
as you don't have the MRECALL option in effect then this message will be
put out once for each macro and only once. If you run your code in batch
then these messages will get written to the log. You then have exactly
what you want in the log -- just those macros that got called and therefore
the ones you need to copy. This is what one of these "MACRO CALLED:"
messages will look like in the log.
MACRO CALLED: readpipe v1.0
I have very carefully made this message consistent for all my macros
so it is easy to strip out these messages or find them using an editor.
I have a sas log on my PC from a program I wrote called t_demog.
This is what I get when I "grep" for lines beginning with "MACRO
CALLED:".
What I want to do with the above list is strip out the third word, which
is the macro and therefore the sas program name, and give it the extension
".sas". "grep" isn't so good for this task. "gawk" is better.
Here goes.
The above list is the macros I want to copy. I want to copy them from
the full library of my sas macros to a new library that will end up containing
just the list of macros shown above. I need to run the above "gawk" command
from the directory my full set of sas macros is in so since t_demog.log
is not in my sas macro library, I will have to refer to it using its full
path name. Below you will see me move to my macros directory and then run
the command above using the t_demog.log full path name.
You can see that the minmacros directory is there when I used
the "echo" command.
Next I want to run the command on the full path name of the log and
copy all those sas macros to the minmacros library. This is how I do it
using the "cp" command with the "-p" ("preserve") option.
I will put the gawk expression in brackets like this "$( )" (using "$(
)" is known as "substitution") and this will make the list of sas macros
available to the "cp" command. After I have done the copy, I will list
out the contents of the minmacros directory and you will see that all the
macros have been copied into there.
You have been shown how to copy just the macros you need, based on the
contents of a sas log, from the main macro library to a new one that will
only contain the macros that you need. If you do not have Linux or a Linux
emulator then how to identify which macros to copy has been explained so
that you can do the copy manually.