Lecture 9 Writing flexible codes with the SAS Macro facility

Lecture 9 Writing flexible codes with the SAS Macro...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: I OWA S TATE U NIVERSITY Department of Animal Science I OWA S TATE U NIVERSITY Department of Animal Science Writing Flexible Codes with the SAS Macro Facility (Chapter in the 7 Little SAS Book) Animal Science 500 Lecture No. 7 September 21, 2010 I OWA S TATE U NIVERSITY Department of Animal Science SAS Macro Development SAS Macros used to be utilized by more advanced SAS Users Today SAS Macros are being used by more and more people Including beginners Using existing Macros Developing your own Macros I OWA S TATE U NIVERSITY Department of Animal Science General Macro Knowledge Macros typically take longer to write and debug than a normal SAS program that you might only use a few times After Macros are developed Make developing maintaining a production program that is used a great deal easier 1. You can have SAS make a change in one part of your program and have SAS echo that throughout the rest of the program 2. Allows you to write a piece of SAS code and reuse it several times either the same day or days later I OWA S TATE U NIVERSITY Department of Animal Science The Macro Processor Compiling submitting your code your SAS program is different than when submitting a SAS Macro Your standard SAS code is submitted and immediately executed Macros have an additional step SAS passes the Macro statement to the macro processor which resolves your macros that generates standard SAS code Called meta programming because you write a program that writes a program I OWA S TATE U NIVERSITY Department of Animal Science Macros and macro variables SAS macro code has two parts 1. Macros 2. Macro variables Name of the Macro is prefixed with a % Name of the Macro variables is prefixed with an & Is like your variable in a data set except it is not associated with a data set and it is always a character variable Can be A variable name A numeral I OWA S TATE U NIVERSITY Department of Animal Science Macros and macro variables Macro is a larger piece of program that may contain complex logic Data Proc Statements Macro Statements %Do %End %IF- %Then/ %Else I OWA S TATE U NIVERSITY Department of Animal Science Macros Macro variable can have different scopes Local defined within the macro Global macro code that is outside of the macro Use global macro variable anywhere in your program A local macro variable can only be used inside the macro Cannot have a global and local macro I OWA S TATE U NIVERSITY Department of Animal Science Invoking or Turning on the Macro Processor Must turn on the MACRO system option in order to use it Macro is usually on by default May be turned off especially true on mainframe computer systems (usually seen in larger businesses, ISU has what some would consider a mainframe but not used by general students SAS runs faster if it does not have to check and see if...
View Full Document

This document was uploaded on 02/14/2012.

Page1 / 33

Lecture 9 Writing flexible codes with the SAS Macro...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online