Copying a minimum set of macros to a library

[Last updated - 22 Aug 2008]

Introduction

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:".
 
$ grep ^"MACRO CALLED:" t_demog.log
MACRO CALLED: readpipe v1.0
MACRO CALLED: titles v1.2
MACRO CALLED: jobinfo v2.0
MACRO CALLED: protinfo v1.3
MACRO CALLED: proginfo v1.2
MACRO CALLED: attrn v1.0
MACRO CALLED: layout2lsps v1.0
MACRO CALLED: verifyb v1.0
MACRO CALLED: xytitles v1.2
MACRO CALLED: casestrmac v1.0
MACRO CALLED: maxtitle v1.0
MACRO CALLED: titlegen v1.0
MACRO CALLED: popfmt v2.1
MACRO CALLED: varfmt v1.0
MACRO CALLED: attrv v1.0
MACRO CALLED: vartype v1.0
MACRO CALLED: openrep v2.0
MACRO CALLED: dequote v1.0
MACRO CALLED: endwith v1.0
MACRO CALLED: unistats v4.7
MACRO CALLED: noquotes v1.0
MACRO CALLED: words v1.0
MACRO CALLED: quotecnt v1.0
MACRO CALLED: unimap v1.1
MACRO CALLED: remove v1.0
MACRO CALLED: windex v1.1
MACRO CALLED: varnum v1.0
MACRO CALLED: quotelst v1.0
MACRO CALLED: varlen v1.0
MACRO CALLED: fmtord v1.0
MACRO CALLED: fmtpath v1.0
MACRO CALLED: unipvals v1.2
MACRO CALLED: unicatrep v3.3
MACRO CALLED: closerep v4.3
MACRO CALLED: pagexofy v5.5

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.
 
$ gawk '/^MACRO CALLED:/ {print $3 ".sas"}' t_demog.log
readpipe.sas
titles.sas
jobinfo.sas
protinfo.sas
proginfo.sas
attrn.sas
layout2lsps.sas
verifyb.sas
xytitles.sas
casestrmac.sas
maxtitle.sas
titlegen.sas
popfmt.sas
varfmt.sas
attrv.sas
vartype.sas
openrep.sas
dequote.sas
endwith.sas
unistats.sas
noquotes.sas
words.sas
quotecnt.sas
unimap.sas
remove.sas
windex.sas
varnum.sas
quotelst.sas
varlen.sas
fmtord.sas
fmtpath.sas
unipvals.sas
unicatrep.sas
closerep.sas
pagexofy.sas

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.
 
$ cd $macros

Roland@DELL1 /cygdrive/c/spectre/macros
$ gawk '/^MACRO CALLED:/ {print $3 ".sas"}' /cygdrive/c/pharma/xenuyama/tokyo/DRUG001/DRUG001C3001/24weeks/progs/t_demog.log
readpipe.sas
titles.sas
jobinfo.sas
protinfo.sas
proginfo.sas
attrn.sas
layout2lsps.sas
verifyb.sas
xytitles.sas
casestrmac.sas
maxtitle.sas
titlegen.sas
popfmt.sas
varfmt.sas
attrv.sas
vartype.sas
openrep.sas
dequote.sas
endwith.sas
unistats.sas
noquotes.sas
words.sas
quotecnt.sas
unimap.sas
remove.sas
windex.sas
varnum.sas
quotelst.sas
varlen.sas
fmtord.sas
fmtpath.sas
unipvals.sas
unicatrep.sas
closerep.sas
pagexofy.sas

Roland@DELL1 /cygdrive/c/spectre/macros

Now I will set up a new macro library called spectre/minmacros. I will use the "echo" command afterwards to make sure it was created.
 
Roland@DELL1 /cygdrive/c/spectre/macros
$ mkdir ../minmacros

Roland@DELL1 /cygdrive/c/spectre/macros
$ echo ../*/
../2008-07-06/ ../macros/ ../minmacros/ ../scripts/ ../work/

Roland@DELL1 /cygdrive/c/spectre/macros

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.
 
Roland@DELL1 /cygdrive/c/spectre/macros
$ cp -p $(gawk '/^MACRO CALLED:/ {print $3 ".sas"}' /cygdrive/c/pharma/xenuyama/tokyo/DRUG001/DRUG001C3001/24weeks/progs/t_demog.log) ../minmacros

Roland@DELL1 /cygdrive/c/spectre/macros
$ ls ../minmacros
attrn.sas       fmtpath.sas      popfmt.sas    titlegen.sas   varlen.sas
attrv.sas       jobinfo.sas      proginfo.sas  titles.sas     varnum.sas
casestrmac.sas  layout2lsps.sas  protinfo.sas  unicatrep.sas  vartype.sas
closerep.sas    maxtitle.sas     quotecnt.sas  unimap.sas     verifyb.sas
dequote.sas     noquotes.sas     quotelst.sas  unipvals.sas   windex.sas
endwith.sas     openrep.sas      readpipe.sas  unistats.sas   words.sas
fmtord.sas      pagexofy.sas     remove.sas    varfmt.sas     xytitles.sas

Roland@DELL1 /cygdrive/c/spectre/macros

Conclusion

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.
 


 
 

Go back to the home page.

E-mail the macro and web site author.