INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 9: Introducing Macro Variables 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Copyright © 2010 SAS Institute Inc. All rights reserved. SAS ® Macros: Top Ten Questions (and Answers!) Kevin Russell –Technical Support Analyst SAS Institute.
Chapter 11: Creating and Using Macro Programs 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Session 7, Chapter 6 From SAS 9.3 Macro Language Reference Macro Expressions P 71.
COSC 120 Computer Programming
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Program Design and Development
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
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.
Computing for Research I Spring 2014 January 22, 2014.
Copyright © 2008, SAS Institute Inc. All rights reserved. SAS ® Macros: Top-Five Questions (and Answers!) Kim Wilson –Technical Support Analyst SAS Institute.
SCSUG Avoiding Hand Cramps: Name2 macro and arrays for related variables November 9, am South Center SAS Users Group Austin, Texas.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Chapter 10:Processing Macro Variables at Execution Time 1 STAT 541 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Writing Maintainable Code with ‘Style’ Allan Page Senior Marketing Analyst Canadian Tire Bank.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.
EIW - ASP Introduction1 Active Server Pages VBScript.
Macro Variable Resolution Enio Presutto York University, Toronto, Canada.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
Introduction to Computer Programming
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
Chapter 7: Macros in SAS  Macros provide for more flexible programming in SAS  Macros make SAS more “object-oriented”, like R 1 © Fall 2011 John Grego.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Expressions and Data Types Professor Robin Burke.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
Hints and Tips SAUSAG Q SORTING – NOUNIQUEKEY The NOUNIQUEKEY option on PROC SORT is a useful way in 9.3 to easily retain only those records with.
Formatting Output.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Two “identical” programs
Variables, Printing and if-statements
Java Programming: From Problem Analysis to Program Design, 4e
11/10/2018.
Chapter 7: Macros in SAS Macros provide for more flexible programming in SAS Macros make SAS more “object-oriented”, like R Not a strong suit of text ©
Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables,
Macro Variable’s scope
PHP.
Defining and Calling a Macro
Global and Local Symbol Tables
Retrieving Macro Variables in the DATA Step
More elements of Python programs
C Programming Getting started Variables Basic C operators Conditionals
Automate Repetitive Programming Tasks: Effective SAS® Code Generators
How Best to Use Macro Quoting Functions?
Fundamental Programming
Introduction to Computer Science
Class code for pythonroom.com cchsp2cs
Presentation transcript:

INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March 28, 2008

Overview/Outline Learn basics of SAS macro facility Two main things –Macro variables – contain character strings –Macros – functions that can be passed variables Useful for automation of repeated tasks Basic introduction for those who know some SAS but little or nothing about macros.

Getting help Open SAS Help and Documentation SAS Products  Base SAS  SAS Macro Reference

First use of the macro facility In this example we –Create a macro variable and assign it a value –Resolve the value of the variable –Use the value to do something in SAS

Turning a block of code into the value of a macro variable The value of a macro variable can be very long. To read a set of SAS statements each ending in a semicolon into a macro variable we need to use the %str quote function. References within the block of statements are resolved when the value is assigned to the macro variable.

Some first macros Starts with %macro name; Ends with %mend; Stuff it does in between Embellishments –One argument –Multiple arguments –Arguments with keywords

From SAS help

A bit fancier macro Number of arguments not specified via use of parmbuff option Arguments put into automatic variable syspbuff Use of a %do %while loop Use of %eval Use of %scan

Building Macro Variables Leading and trailing blanks Imbedded blanks Use of period to force resolution Combining macro variables with and without blanks

Scope Local versus global scope Forcing local or global scope Using %put to find out what is going on with specific variables Using %put to get symbol tables

Scopes of Macro Variables Previous Page | Next Page | Top of Page Copyright 2003 by SAS Institute Inc., Cary, NC, USA. All rights reserved. From SAS help

Some debugging tips and tricks Take small steps and work modularly Check for common errors Getting out of macro black holes – *'; *"; *); */; %mend; run; Using system options to get output useful debugging

Even more on resolving macro variables && and &&& Using &&& to pass the name of a macro variable and resolve it and then scan through the result (using %scan or %qscan)

A bit more on quoting functions Special characters and mnemonics that might need to be masked. Our old problem with ; and solving it with %str. Other quoting functions to solve problems %str cannot.

Logical expressions and conditional execution %IF expression %THEN statement; Logical conditions Integer arithmetic in logical conditions Forcing floating point arithmetic by %sysevalf

Passing values between macro and data set variables Standard data set variable assignment using macro resolution; Use of symget function to pass macro variable value to data set variable Use of symput routine to pass data set variable to macro variable Use of select as analog of symput for Proc SQL