I've Got to Hand It To You: Portable Programming Techniques - Art Carpenter, California Occidental Consultants
As technology expands, we have the need to create programs that can be handed off – to clients, to regulatory agencies, to parent companies, or to other projects, and handed off with little or no modification by the recipient. Minimizing modification by the recipient often requires the program itself to self-modify. To some extent the program must be aware of its own operating environment and what it needs to do to adapt to it.
There are a great many tools available to the SAS® programmer, which will allow the program to self-adjust to its own surroundings. These include location-detection routines, batch files based on folder contents, the ability to detect the version and location of SAS, programs that discern and adjust to the current operating system and the corresponding folder structure, the use of automatic and user defined environmental variables, and macro functions that use and modify system information.
Need to create a portable program? We can hand you the tools.
There are a great many tools available to the SAS® programmer, which will allow the program to self-adjust to its own surroundings. These include location-detection routines, batch files based on folder contents, the ability to detect the version and location of SAS, programs that discern and adjust to the current operating system and the corresponding folder structure, the use of automatic and user defined environmental variables, and macro functions that use and modify system information.
Need to create a portable program? We can hand you the tools.
Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language - Art Carpenter, California Occidental Consultants
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.
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.
About the Author
Art Carpenter is a SAS Certified Advanced Professional Programmer and his publications list includes five books and numerous papers and posters presented at SAS Global Forum, SUGI, PharmaSUG, WUSS, and other SAS user conferences. Art has been using SAS since 1977 and has served in various leadership positions in local, regional, and international user groups. Art is in the process of becoming mostly retired.
Recent publications are listed on his sasCommunity.org Presentation Index page. http://sascommunity.org/wiki/Presentations:ArtCarpenter_Papers_and_Presentations |