SAS

Macros for download

I have made a number of macros that I use frequently in my own use of SAS. I plan to put out more of these later, but some of these need some improvement first: here are a few that I consider generally useful.

Main macros
User assistance macros
%Help
This gives help on which macros are available in the SASAUTOS catalogues, and prints help on these (top commented block in the files) to the log.
Requires: %sasautos
%SummarizeLog
Parses the log and extracts warnings and errors. Reports these in a brief format. This is useful if you have a long log and wish to find if there were any reported problems.
%RunOnce
Takes quoted SAS code as a parameter and runs it once. Afterwards, it will not be rerun unless a rerun is triggered by some other event: e.g. change in the code, or by the rerunning of some other RunOnce on which it depends. This is particularly useful if you have some code that needs to be run at the start, e.g. to generate data, but takes a while to run: an alternative to commenting it out.
Requires: %ComputeHash
Data handling
%ExportTable
Writes contents of a SAS data set to a text file. Format of output is customizable, including column separator, column labels, formats, which columns are included and their order.
Requires: %DoOver
%FileTableFormat
Parse a text file which contains a data table, try to interpret the format, and generate data step code for reading it.
Data analysis macros
%QuantileNormalize
Quantile normalization. NB: Experimental!
Utility macros
%Seq
Loop over integers (e.g. p,...,q) substituting the integer into a given expression. Similar to %DoOver which loops over an arbitrary list of words/strings.
Requires: %Substitute
%DoOver
Loops over a list of words/strings, substituting them into a given expression. Similar to %Seq which loops over integers p,...,q.
Requires: %Substitute
%Substitute
Substitute one substring with another. Runs substitutions until no more occurences exist.
Supporting macros
%sasautos
%ComputeHash
Last modified November 23, 2008.