1 / 14

Jacob D. Gundrum Department of Medical Research Gundersen Lutheran Medical Foundation La Crosse, Wisconsin, USA

A Stored Macro Pack: The Beginnings. Jacob D. Gundrum Department of Medical Research Gundersen Lutheran Medical Foundation La Crosse, Wisconsin, USA. Background. Repetitive programming tasks exist. Repeated tasks can be coded as macro(s). Macros can be compiled and stored.

lumina
Download Presentation

Jacob D. Gundrum Department of Medical Research Gundersen Lutheran Medical Foundation La Crosse, Wisconsin, USA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Stored Macro Pack: The Beginnings Jacob D. GundrumDepartment of Medical ResearchGundersen Lutheran Medical FoundationLa Crosse, Wisconsin, USA

  2. Background • Repetitive programming tasks exist. • Repeated tasks can be coded as macro(s). • Macros can be compiled and stored. • Stored/compiled macros can be referenced from a session.

  3. So • How about creating a directory of commonly used macros? • No need to reinvent the wheel or produce another one. • Just use the ones you have.

  4. Intent To provide: • some framework to create a macro pack tool kit. • some examples to start with.

  5. Method / Organization Project 1 Project 2 Project n Create a directory with stored/compiled macros 1. Open path to stored macros 2. Make macro calls as needed %macro a(…) %macro b(…) %macro c(…) … %macro z(…) 1. Open path to stored macros 2. Make macro calls as needed … 1. Open path to stored macros 2. Make macro calls as needed

  6. Two Main Parts • Macro code, where you • Create source code then compile and store the compiled macro • Project / session code, where you • open the path to the compiled / stored macros • call / invoke the those macros

  7. Part 1: Macro Code Project 1 Project 2 Project n Create a directory with stored/compiled macros 1. Open path to stored macros 2. Make macro calls as needed %macro a(…) %macro b(…) %macro c(…) … %macro z(…) 1. Open path to stored macros 2. Make macro calls as needed 1. Open path to stored macros 2. Make macro calls as needed

  8. Storing and Compiling a Macro To compile and store a macro, simply execute the 2 code sets below: • Tell SAS where to put the compiled macro (run once per session): libname <name> ‘<path to where to put the compiled macro>'; options mstoredsasmstore=<name>; • For each macro, add the “/ store” command at the end of the macro definition line (run macro code as many times as you need in a session): %macro x(<parameter list>) / store; <macro code> %mend x;

  9. Storing and Compiling a Macro (cont.) Notes: • The stored macro is compiled. • i.e. it’s not stored as source code • There appear to be options that I have not investigated thus far. • check out further documentation

  10. Part 2: Project / Session Code Project 1 Project 2 Project n Existing directory with stored compiled macros • Open path to stored macros • Make macro calls as needed %macro a(…) %macro b(…) %macro c(…) … %macro z(…) • Open path to stored macros • Make macro calls as needed • Open path to stored macros • Make macro calls as needed

  11. Using the Stored Macros in a Project To use any of the macros you have stored and compiled: • Tell SAS where the compiled macros are located and that you want to use them: libname <name> ‘<path to where the compiled macros exist>'; options mstored sasmstore=<name>; (execute the above statement once per session) • At any point in the session, just call the macros as usual: • %x(<parameter list>);

  12. Examples for Data Preparation • Example macros: • summarize missing values • See the EmptySummary.sas file • identify order errors in an ordered sequence of variables • See the CheckOrder.sas file • convert raw variables to their formatted versions • See the Format_To_Raw.sas file • Why data prep macros? • time consuming • repetitious • common issue

  13. Reference • SAS 9.2 Documentation • Search for: Introduction to Storing and Reusing Macros

  14. The End Thanks for Watching and Listening

More Related