slide1 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Jacob D. Gundrum Department of Medical Research Gundersen Lutheran Medical Foundation La Crosse, Wisconsin, USA PowerPoint Presentation
Download Presentation
Jacob D. Gundrum Department of Medical Research Gundersen Lutheran Medical Foundation La Crosse, Wisconsin, USA

Loading in 2 Seconds...

play fullscreen
1 / 14

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


  • 129 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Jacob D. Gundrum Department of Medical Research Gundersen Lutheran Medical Foundation La Crosse, Wisconsin, USA' - lumina


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide2

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.
slide3

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.
slide4

Intent

To provide:

  • some framework to create a macro pack tool kit.
  • some examples to start with.
slide5

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

slide6

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
slide7

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

slide8

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;

slide9

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
slide10

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
slide11

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>);
slide12

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
slide13

Reference

  • SAS 9.2 Documentation
    • Search for: Introduction to Storing and Reusing Macros
slide14

The End

Thanks for Watching and Listening