Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language
The SAS macro language gives us the power to create tools that to a large extent can think for themselves. How often have you used a macro that required your input and you thought to yourself "Why do I need to provide this information when SAS already knows it?" SAS may well already know what you are being asked to provide, but how do we direct our macro programs to self-discern the information that they need? Fortunately there are a number of functions and other tools within SAS that can intelligently provide our programs with the ability to find and utilize the information that they require.
If you provide a variable name, SAS should know its type and length; given a data set name, the list of variables should be known; given a library or libref, the full list of data sets that it contains should be known. In each of these situations there are functions that can be utilized by the macro language to determine and return these types of information. Given a libref these functions can determine the library’s physical location and the list of all the data sets it contains. Given a data set they can return the names and attributes of any of the variables that it contains. These functions can read and write data, create directories, build lists of files in a folder, and even build lists of folders.
Maximize your macro's intelligence; learn and use these functions.
View the PDF for this paper.