Two “identical” programs

Slides:



Advertisements
Similar presentations
Chapter 9: Introducing Macro Variables 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
String Escape Sequences
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Variable & Constants. A variable is a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
Computing for Research I Spring 2014 January 22, 2014.
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.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
1 Chapter 1: Introduction 1.1 Course Logistics 1.2 Purpose of the Macro Facility 1.3 Program Flow.
Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Chapter 2 Variables.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
28 Formatted Output.
Bill Tucker Austin Community College COSC 1315
C++ First Steps.
The Second C++ Program Variables, Types, I/O Animation!
Chapter 2 Variables.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
CSC201: Computer Programming
Introduction to the C Language
Python Let’s get started!.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2, Part I Introduction to C Programming
Basic Elements of C++.
A First Book of ANSI C Fourth Edition
Intro to PHP & Variables
Java Programming: From Problem Analysis to Program Design, 4e
Basic Elements of C++ Chapter 2.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Introduction to the C Language
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Number and String Operations
Chapter 2: Basic Elements of Java
Creating Macro Variables in the DATA Step
Macro Variable’s scope
Chapter 2 Variables.
Defining and Calling a Macro
3 Iterative Processing.
Topics Designing a Program Input, Processing, and Output
elementary programming
CHAPTER 2: COMPONENTS OF PROGRAMMING LANGUAGE
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Chapter 2 Variables.
Presentation transcript:

Two “identical” programs proc logistic data=s5238.chdage outest=betas; model chd=age; run; proc logistic data=s5238.chdage outest=betas ; model chd=age;run; These programs give exactly the same answer – Why?

3 Program Flow Submit=>Input Stack=>Tokenization=>Compilation=>Execution

Program Flow A SAS program can be any combination of: DATA steps and PROC steps global statements SAS Component Language (SCL) Structured Query Language (SQL) SAS macro language When you submit a program, it is copied to a memory location called the input stack. Remind students here about the compile phase and the execution phase, which they learned in Prg1 and Prg2. Then tell students that we are going to learn what SAS does even before the compile phase.

Program Flow Input Stack SUBMIT Command data bonus; set orion.staff; bonus=salary*.1; run; proc print;

Program Flow When SAS code is in the input stack, a component of SAS called the word scanner reads the text in the input stack, character by character, left to right, top to bottom and breaks the text into fundamental units called tokens data bonus ; Word Scanner Note that in this "program flow" animation/demo, there is no macro code. This is just the normal flow of straight SAS code. Later in this chapter, we will introduce the idea of macro triggers and show how this alters the program flow. set orion.staff; bonus=salary*.1; run; proc print; Input Stack

Program Flow The word scanner passes the tokens, one at a time, to the appropriate compiler, as the compiler demands. Compiler data bonus; set orion . staff ; Word Scanner bonus=salary*.1; run; proc print; Input Stack

Program Flow The compiler: Requests tokens until it receives a semicolon Performs a syntax check on the statement Repeats this process for each statement SAS: Suspends compilation when a step boundary is encountered Executes the compiled code if there are no compilation errors Repeats this process for each step

Tokenization The word scanner recognizes four classes of tokens: Name tokens Special tokens Literal tokens Number tokens Students might wonder here: Why do I need to know this? Assure them that we are leading up to the important concept of Macro Triggers, which consists of certain token combinations.

Name Tokens Name tokens contain one or more characters beginning with a letter or underscore and continuing with underscores, letters, or numerals. Examples: infile _n_ item3 univariate dollar10.2 Format and informat names contain a period.

Special Tokens Special tokens can be any character, or combination of characters, other than a letter, numeral, or underscore. Examples: This list is not all-inclusive. * / + - ** ; $ ( ) . & % @ # = ||

Literal Tokens A literal token is a string of characters enclosed in single or double quotation marks. Examples: 'Any text' "Any text" The string is treated as a unit by the compiler.

Number Tokens Number tokens can be integer numbers, including SAS date constants floating point numbers, containing a decimal point and/or exponent. Examples: 3 3. 3.5 -3.5 '01jan2009'd 5E8 7.2E-4

Tokenization A token ends when the word scanner detects one of the following: the beginning of another token a blank after a token Blanks are not tokens. Blanks delimit tokens. The maximum length of a token is 32,767 characters.

Input Stack Tokens var x1-x10 z ; var x1 - x10 z ;

Input Stack Tokens title 'Report for May'; 1. title 2. 'Report for May' 3. ;

Macro Triggers During word scanning, two token sequences are recognized as macro triggers: %name-token a macro statement, function, or call &name-token a macro variable reference Finally! This is what we've been leading up to! The word scanner passes macro triggers to the macro processor.

Program Flow (Review) Compiler Word Scanner Input Stack

The Macro Processor The macro processor executes macro triggers, including macro language statements, macro functions, macro calls, and macro variable resolution, requesting tokens as necessary. Compiler Macro Processor Word Scanner Input Stack

Macro Statements Begin with a percent sign (%) followed by a name token End with a semicolon Represent macro triggers Are executed by the macro processor %let macvar=AMacroVariableValue; %put The value of macvar is: &macvar;

The %PUT Statement Writes text to the SAS log Writes to column one of the next line Writes a blank line if no text is specified General form of the %PUT statement: %PUT text; The instructor may wish to compare %PUT with PUT. The latter is a datastep statement. The former is a macro language statement. Also, this is a good time to say more generally that in the macro language, quote marks are rarely used. More on that subject later. Quotation marks are not required around text in %PUT statements. %PUT statements are valid in open code (anywhere in a SAS program).

%put Hello World!; The %PUT Statement Example: Use a %PUT statement to write text to the SAS log. %put Hello World!;

Program Flow The %PUT statement is submitted. Compiler Macro Processor Word Scanner Here is where we see that a macro trigger alters the program flow. Note that this is a macro language statement, not a SAS statement or step, as in the previous demo. Input Stack %put Hello World!; ...

Program Flow The statement is tokenized. Compiler Macro Processor Word Scanner % put Hello World ! ; Input Stack ...

Program Flow When a macro trigger is encountered, it is passed to the macro processor for evaluation. Compiler Macro Processor Word Scanner %put Hello World ! ; Nothing is sent to the SAS compiler, because there are no SAS statements. Input Stack ...

Program Flow The macro processor requests tokens until a semicolon is encountered. It then executes the macro statement. Compiler Macro Processor Word Scanner %put Hello World!; Input Stack ...

3 Program Flow Input Stack=>Tokenization=>Compilation=>Execution The macro facility

“The macro facility is a text processing facility for automating and customizing SAS code. The macro facility helps minimize the amount of SAS code you must type to perform common tasks.”