Global and Local Symbol Tables

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Chapter 9: Introducing Macro Variables 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 11: Creating and Using Macro Programs 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
VBA Modules, Functions, Variables, and Constants
Introduction to Structured Query Language (SQL)
Tutorial 6 & 7 Symbol Table
Introduction to Structured Query Language (SQL)
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
1 Chapter 3: Macro Definitions 3.1 Defining and Calling a Macro 3.2 Macro Parameters 3.3 Macro Storage (Self-Study)
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.
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.
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith.
1 Chapter 5: Macro Programs 5.1 Conditional Processing 5.2 Parameter Validation 5.3 Iterative Processing 5.4 Global and Local Symbol Tables.
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Creating and Managing Indexes Using Proc SQL Chapter 6 1.
INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
A SASInstitute SAS Advanced Programming Exam for SAS 9 Thousands of IT Professionals before you have already passed their A certification exams.
Slide 1 PHP Arrays and User Defined Functions ITWA133.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
Macro Variable Resolution Enio Presutto York University, Toronto, Canada.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
Variables and control statements in PL\SQL Chapter 10.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
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.
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata RDBMS Concepts.
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Using the Macro Facility to Create HTML, XML and RTF output Rick Langston, SAS Institute Inc.
Two “identical” programs
Creating Macro Variables in SQL (Review)
Chapter 18: Modifying SAS Data Sets and Tracking Changes
ISC440: Web Programming 2 Server-side Scripting PHP 3
Conditional Processing
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 ©
Functions BIS1523 – Lecture 17.
3 Macro Parameters.
Indirect References to Macro Variables
variables and control statements in PL\SQL
Creating Macro Variables in the DATA Step
Macro Variable’s scope
Defining and Calling a Macro
Retrieving Macro Variables in the DATA Step
3 Iterative Processing.
Scope Rules and Storage Types
3 Parameter Validation.
Lecture 5: Functions and Parameters
CHAPTER 21 LOOPS 1.
The structure of programming
Database SQL.
Thinking procedurally
Programming II Vocabulary Review Loops & functions
Parameters and Arguments
Presentation transcript:

Global and Local Symbol Tables 4 Global and Local Symbol Tables

%macro simp proc sql; select count(*) into :numobs from fram.frex4 ; quit; %mend; %simp %put &numobs;

%macro simp; %global numobs; proc sql; select count(*) into :numobs from fram.frex4 ; quit; %mend; %simp %put &numobs;

The difference between global and local symbol tables.

The Global Symbol Table (Review) The global symbol table is Created during SAS initialization Initialized with automatic macro variables Deleted at the end of the session. This material was covered in chapter 2.

The %GLOBAL Statement %GLOBAL macro-variable1 macro-variable2 . . . ; The %GLOBAL statement adds one or more macro variables to the global symbol table with null values. It has no effect on variables already in the global table. It can be used anywhere in a SAS program.

The Local Symbol Table Local macro variables can be created within a macro definition: %LET statement DATA step SYMPUTX routine PROC SQL SELECT statement INTO clause %LOCAL statement Only the last bullet item is truly new. The first three items were implied, but never explicitly stated.

The Local Symbol Table A local symbol table is Created when a macro with a parameter list is called or a local macro variable is created during macro execution Deleted when the macro finishes execution. Macros that do not create local variables do not have a local table. This material was covered in chapter 3.

The %LOCAL Statement %LOCAL macro-variable1 macro-variable2 . . . ; The %LOCAL statement adds one or more macro variables to the local symbol table with null values. It has no effect on variables already in the local table. It can appear only inside a macro definition. The last bullet should be emphasized.

Rules for Creating and Updating Variables When the macro processor receives a request to create or update a macro variable during macro execution, the macro processor follows these rules: %let macvar=value; Does MACVAR already exist in the local table? Update MACVAR in the local table. Yes No In other words, the macro variable will be created in the executing macro's local table UNLESS IT ALREADY EXISTS in another table. The %local statement on the previous slide guarantees that the macro variable will be created in the executing macro's local table and NOT over-write a like-named macro variable in another table. Does MACVAR already exist in the global table? Update MACVAR in the global table. Yes No Create MACVAR in the local table.

Rules for Resolving Variables To resolve a macro variable reference during macro execution, the macro processor follows these rules: &macvar Does MACVAR exist in the local table? Yes Retrieve from local table. No Does MACVAR exist in the global table? In other words, check local first. Yes Retrieve from global table. No Return tokens to word scanner. Issue a warning to SAS log: Apparent symbolic reference MACVAR not resolved.

The SYMPUTX Routine The optional scope argument of the SYMPUTX routine specifies where to store the macro variable: G specifies the global symbol table. L specifies the current macro's local symbol table. If no local symbol table exists for the current macro, a local symbol table is created. CALL SYMPUTX(macro-variable, text <,scope>); The SCOPE argument is recommended ANY TIME the symputx routine is used inside a macro definition.

The %LOCAL Statement Declare the index variable of a macro loop as a local variable to prevent accidental contamination of a like-named macro variable in the global table or another local table. %macro putloop; %local i; %do i=1 %to &numrows; %put Country&i is &&country&i; %end; %mend putloop; Recommended practice.