Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables,

Slides:



Advertisements
Similar presentations
Chapter 11: Creating and Using Macro Programs 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Advertisements

Session 7, Chapter 6 From SAS 9.3 Macro Language Reference Macro Expressions P 71.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
TES3111 Oct 2001 Data Structures S-Expression - Symbolic expression. It can be an Atom, a List or a collection of S- Expression enclosed by (…) Atom -
Basic Elements of C++ Chapter 2.
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
SCSUG Avoiding Hand Cramps: Name2 macro and arrays for related variables November 9, am South Center SAS Users Group Austin, Texas.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Computer Science 101 Introduction to Programming.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Doing math In java.
Macro Processors Basic Functions Machine-Independent Features Design Options Implementation Examples.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
 To find the numerical value of the expression, simply substitute the variables in the expression with the given number. Evaluate: 2x + 7, if x = 4 Substitute.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
Fundamental Programming Fundamental Programming Data Processing and Expressions.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Arithmetic Instructions. Integer and Float Conversions.
Relational Operator and Operations
Arithmetic Expressions
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Chapter 3 Syntax, Errors, and Debugging
Operators and Expressions
Data Types and Conversions, Input from the Keyboard
Chapter 3: Variables, Functions, Math, and Strings
Computing Fundamentals
Java Primer 1: Types, Classes and Operators
Basic Elements of C++.
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Test Review Computer Science History
Data Conversion & Scanner Class
Design & Technology Grade 7 Python
-by Nisarg Vasavada (Compiled*)
The Selection Structure
Two “identical” programs
Type Conversion, Constants, and the String Object
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Basic Elements of C++ Chapter 2.
Expressions and Interactivity
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Introduction to C++ Programming
Arithmetic Expressions & Data Conversions
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
C Operators, Operands, Expressions & Statements
Defining and Calling a Macro
Lecture3.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CSCI-N 100 Dept. of Computer and Information Science
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
How Best to Use Macro Quoting Functions?
Terminal-Based Programs
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Lecture 5 SQL FUNCTIONS.
Operator King Saud University
is multiplied by a variable of type to yield a result of type
Arithmetic Expressions & Data Conversions
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables, macro functions, or macro calls. Text expressions are resolved to generate text. Here are some examples of text expressions: &BEGIN %GETLINE &PREFIX.PART&SUFFIX %UPCASE(&ANSWER)

Macro Expressions Logical expressions and arithmetic expressions are sequences of operators and operands forming sets of instructions that are evaluated to produce a result. An arithmetic expression contains an arithmetic operator. A logical expression contains a logical operator.

Macro Language Elements that Evaluate Arithmetic and Logical Expressions %DO macro-variable=expression %TO expression<%BY expression>; %DO %UNTIL (expression); %DO %WHILE (expression); %EVAL (expression); %IF expression %THEN statement; %QSCAN (argument, expression<,delimiters>) %QSUBSTR (argument, expression<,expression>) %SCAN (argument, expression,<delimiters>) %SUBSTR (argument, expression<,expression>) %SYSEVALF (expression, conversion-type)

Example %let A=2; %let B=5; %let operator=+; %put The result of &A &operator &B is %eval(&A &operator &B).; When you submit these statements, the %PUT statement writes this line to the log: The result of 2 + 5 is 7.

Macro Language Operators

Examples %let a=%eval(1+2); %let b=%eval(10*3); %let c=%eval(4/2); %let i=%eval(5/3); %put The value of a is &a; %put The value of b is &b; %put The value of c is &c; %put The value of I is &i; When you submit these statements, the following messages appear in the log: The value of a is 3 The value of b is 30 The value of c is 2 The value of I is 1 %let d=%eval(10.0+20.0); /*INCORRECT*/ Because the %EVAL function supports only integer arithmetic, the macro processor does not convert a value containing a period character to a number, and the operands are evaluated as character operands. This statement produces the following error message: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 10.0+20.0

Examples %let a=%sysevalf(10.0*3.0); %let b=%sysevalf(10.5+20.8); %let c=%sysevalf(5/3); %put 10.0*3.0 = &a; %put 10.5+20.8 = &b; %put 5/3 = &c; The %PUT statements display the following messages in the log: 10.0*3.0 = 30 10.5+20.8 = 31.3 5/3 = 1.6666666667 When the %SYSEVALF function evaluates arithmetic expressions, it temporarily converts the operands that represent numbers to floating point values.

Examples The %SYSEVALF function provides conversion type specifications: BOOLEAN,INTEGER, CEIL, and FLOOR. For example, the following %PUT statements return 1, 2, 3, and 2 respectively: %let a=2.5; %put %sysevalf(&a,boolean); %put %sysevalf(&a,integer); %put %sysevalf(&a,ceil); %put %sysevalf(&a,floor);