Example: tourism industry

SUGI 27: Building and Using Macro Libraries - SAS

Paper 17-27 Building and Using Macro LibrariesArthur L. Carpenter, California Occidental ConsultantsABSTRACTW hile many users take advantage of the SAS Macro Language, few take full advantage of itscapabilities to build and maintain Libraries ofmacros. Management of large numbers ofmacros can be problematic. Names andlocations must be remembered, changes must bemanaged, duplication and variations of individualmacros must be monitored, and efficiency issuesmust be taken into consideration. Theseproblems come even more to the forefront whenmacros are shared among programmers -especially in a networked Libraries allow you to control and managethe proliferation of your macros. Libraries canconsist of a formal use of the %INCLUDE statement, a group of programs defining macrosthat can be automatically called, or evencollections of macros that were previouslycompiled and then Libraries are extremely useful, and notreally all that complicated.

Paper 17-27 Building and Using Macro Libraries Arthur L. Carpenter, California Occidental Consultants ABSTRACT While many users take advantage of the SAS®

Tags:

  Using, Building, Macro, Libraries, Building and using macro libraries

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of SUGI 27: Building and Using Macro Libraries - SAS

1 Paper 17-27 Building and Using Macro LibrariesArthur L. Carpenter, California Occidental ConsultantsABSTRACTW hile many users take advantage of the SAS Macro Language, few take full advantage of itscapabilities to build and maintain Libraries ofmacros. Management of large numbers ofmacros can be problematic. Names andlocations must be remembered, changes must bemanaged, duplication and variations of individualmacros must be monitored, and efficiency issuesmust be taken into consideration. Theseproblems come even more to the forefront whenmacros are shared among programmers -especially in a networked Libraries allow you to control and managethe proliferation of your macros. Libraries canconsist of a formal use of the %INCLUDE statement, a group of programs defining macrosthat can be automatically called, or evencollections of macros that were previouslycompiled and then Libraries are extremely useful, and notreally all that complicated.

2 If you are notcurrently Using them as part of your macroprogramming efforts, read on!KEYWORDS%INCLUDE, autocall, Libraries , compiledmacros, SASMACR catalog, SASAUTOS,SASMSTOREINTRODUCTIONThe use of macros is essential to an automatedand flexible system. This implies that the controlof the Macro code is very important to themaintenance of the application. All to oftenmacro definitions become buried within theprograms that use them. The result is often aproliferation of multiple versions of similarmacros in multiple programs, each with its owndefinition of the Macro . Parallel code, twoprograms or macros that do essentially the samething, is an especially difficult problem in largeapplications that are maintained by multipleprogrammers. Even when there is only oneprogrammer, there is a tendency to clone aprogram ("with slight modifications").

3 Will eachversion be updated each time a bug is found?Who makes sure that the update happens? Arethe various versions of the Macro documented?These problems are avoided by placing thedefinition in a Macro Libraries are used to avoid the problem ofmacro cloning by providing a single location forall Macro definitions. Rather than cloning themacro, it is adapted (generalized) to fit each ofits calling programs and then stored in one of thelibraries. Once in a library, there will only ONEmacro definition to maintain, and it can be usedby as many programs as is needed. Obviouslythis requires documentation as well as of the solution is to place ALL macrodefinitions in a common library, which isaccessible to all programs in the way no Macro definition will be 'buried'within a are three types of Macro Libraries ;%INCLUDE, Compiled Stored Macros,AUTOCALL Macros.

4 Each has its advantagesand disadvantages, and best of all they can beused in conjunction with each other!It is important to understand the behavior ofthese Libraries , how they are setup, and how theySUGI 27 Advanced Tutorialsinteract with each least sophisticated approach to setting up amacro library is obtained through the use of%INCLUDE files which store Macro was often the only viable type of library inearlier (pre V6) versions of SAS, and not a fewSAS programmers have failed to make thetransition to true Macro speaking the use of the %INCLUDE does not actually set up a Macro library. The%INCLUDE statement points to a file and whenthe statement is executed, the indicated file (be ita full program, Macro definition, or a statementfragment) is inserted into the calling program atthe location of the call.

5 When Using the%INCLUDE to build a Macro library, theincluded file will usually contain one or moremacro you can identify the file to be includeddirectly from within the %INCLUDE statement,it is usually done indirectly through the use of macdef1 c:\mymacros\ ;..%include macdef1;..% way to build a library or collection of filesthat are to be included , is to place them in onecentral location. This way they will be easier tofind and maintain. Some users of includelibraries will indicate that these file are to be included , and therefore might not be completeprograms, by Using an extension of INC insteadof SAS. While Using an extension of INC in noway hampers the file s use by SAS, windowsusers should be aware that the file will not bemarked by a SAS registered was mentioned above the included file cancontain any snippet of SAS code.

6 Within thecontext of this paper however, we are interestedin Building Macro Libraries and to do this theincluded file would contain a Macro Thereare a couple of efficiency issues that the user ofinclude Libraries should a given file should not contain morethan one Macro definition, and the Macro beingcalled should not be called from within theincluded code. The first is important because ifthe file contains multiple Macro definitions, thenall the definitions must be loaded, and compiled,just to use one of the macros. Of course if allthe macros will eventually be used this does notreally matter. Secondly if the Macro call isplaced within the included code, the code willneed to be re-included (and the macrorecompiled) each time the Macro is to be greatest disadvantage of Using the%INCLUDE in a large application is trackingand maintaining thefilerefs that point to theindividual files.

7 While this is less of a problem instatic systems, it is still non-trivial. This issuevirtually goes away with the use of the othermacro library alternatives discussed STORED MACROSM acros are always compiled before they areexecuted and it is possible to store the compiledcode for future use. Compiled macros are storedin a catalog named SASMACR, and by defaultthis catalog is stored in the WORK library. Eachcompiled Macro is stored with the entry type ofMACRO and with an entry name correspondingto the name of the Macro . When a Macro iscalled, SAS automatically searches this catalogfor the compiled version of the Macro that wascalled. Permanently compiled stored macros arealso written to a SASMACR catalog, but thiscatalog is stored in a different (permanent) ability to store and make use of compiledSUGI 27 Advanced Tutorialsstored macros is by default turned off.

8 The userturns on the abilty to make use of compiledstored macros with the system optionMSTORED (NOMSTORED turns it off). Thelibrary that is to be used to store the permanentSASMACR catalog is specified by Using theSASMSTORE= following OPTIONS statement turns on theuse of compiled stored macros and designatesthe PROJSTOR librefas the catalog mstored sasmstore=projstor;Unlike the AUTOCALL Libraries discussed next,you cannot use more than one location referencewith the SASMSTORE option, therefore, if youdo want to search multiple catalogs, you need touse either a concatenatedlibrefor aconcatenated following designates the twolibrefsPROJSTOR and ALLMSTOR as the locationsthat are to be searched for the compiled storedmacro catalog by concatenating the twolocations into a singlelibref.

9 If the compiledmacro is in more than one catalog, the definitionfound first will be used (read left to right).libname projstor 'c:\temp';libname allmstor 'f:\junk';libname multi (projstor, allmstor);options mstored sasmstore=multi;By default the compiled Macro is stored You redirect this locationat compile time through the use of the /STORE option on the % Macro statement. For theSASMSTORE definition above, the macroAERPT shown below, will be stored in aerpt(dsn, stdate, aelist) / store;The use of compiled stored macros is notwithout problems. The developer must makesure that a Macro does not exist in more thanone catalog or if it does (on purpose, of course)that the search order of the catalogs is , since it is not possible to reconstruct thecode used to create the compiled Macro , thedeveloper must make sure that the code iscorrectly maintained independently from theSASMACR highlights a second problem for theselibraries.

10 The compiled macros are all in onelocation, the SASMACR catalog, however thecode itself could be anywhere. Usuallydevelopers that use compiled stored macrolibraries will also have a central location to storethe source code. A logical location is in thesame directory as the SASMACR FACILITYWhen a requested Macro is not found in aSASMACR catalog, the AUTOCALL library issearched. Much like an %INCLUDE file, thislibrary contains the Macro definitions in the formof SAS code. When a Macro is called, SASsearches for a file with the SAME name as thename of the Macro in the specified AUTOCALL location. The code in the corresponding file isthen submitted for processing. Since this filecontains the Macro definition, the Macro is thencompiled and made available for Windows this location is a folder andeach Macro definition is an individual file.


Related search queries