bmtry 789 lecture 10 sas macro facility l.
Skip this Video
Loading SlideShow in 5 Seconds..
BMTRY 789 Lecture 10: SAS MACRO Facility PowerPoint Presentation
Download Presentation
BMTRY 789 Lecture 10: SAS MACRO Facility

Loading in 2 Seconds...

play fullscreen
1 / 17

BMTRY 789 Lecture 10: SAS MACRO Facility - PowerPoint PPT Presentation

  • Uploaded on

BMTRY 789 Lecture 10: SAS MACRO Facility. Annie N. Simpson, MSc. What's a MACRO?. MACRO: a rule or pattern that specifies how a certain input sequence should be mapped to an output sequence according to a defined procedure. (Wikipedia). Facts about Macros.

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

PowerPoint Slideshow about 'BMTRY 789 Lecture 10: SAS MACRO Facility' - pia

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
what s a macro
What's a MACRO?


a rule or pattern that specifies how a certain input sequence should be mapped to an output sequence according to a defined procedure.


facts about macros
Facts about Macros
  • SAS macro code is separate from SAS code
  • Allows you to do repetitive assignments where the only difference is a variable (s)
  • Enables great flexibility in SAS programming and saves time
macros from beginning to mend
Macros from beginning to %Mend
  • The % typically identifies a macro command
  • Code enclosed within %MACRO and %MEND are viewed by SAS as a program
  • You can (almost) freely mix regular SAS code with Macro code
  • Once you define a macro program, you then need to “call” (or invoke) it
  • You call a macro by %«macro name» (you don't use the word MACRO when you call it...only when you are defining it)
macro variable
  • Macro variables are either defined by a %LET statement or as parameters within a macro program
  • A macro variable is referenced in your program by preceding the macro variable name with an ampersand (&).
lab data example
LAB DATA Example
  • Consider you want to create BOXPLOTS for several lab tests:
    • Hemoglobin, Hematocrit, Platelets
  • Each BOXPLOT should have its own title and axis.
  • Of course, we will use SAS for this
adding parameters to macros
Adding Parameters to Macros
  • Once you identify potential parameters, list them out in parenthesis separated by a comma in the MACRO declaration
  • When you call the MACRO, you pass the values to the MACRO again in parenthesis separated by commas
what happens
What happens?
  • What happens if you run this program?
  • ??
  • Let's check the log
don t forget to call
Don’t forget to CALL!
  • Nothing happened because we didn't CALL the macro
  • Here's what the log reads after we call %labs
sas log will look different
  • Note, in the SAS MACRO log, you do not get the NOTES interspersed with the PROC statements
  • Why? Because the entire MACRO gets compiled into a bundle of code
  • You can “look” into the bundle of code by using the MPRINT system option
  • On occasion, you may want to “look inside” a macro variable to see what value is stored
  • This often occurs during debugging parameters
  • You accomplish this by the %Put statement followed by the variable name
  • %Put writes values to the SAS LOG
  • There are also special %Put statements:

%put _all_

%put _user_

%put _local_

%put _global_

  • Creates a macro variable and assigns it a value
  • %LET can be used inside or outside of a macro program


%LET macro-variable =<value>;


  • MACROS save time
  • Necessary when have a large number of variables.
    • Imagine running a regression for every variable when you have 100+ variables!
  • Programs are reusable and easier to understand.