Session 7, Chapter 6 From SAS 9.3 Macro Language Reference Macro Expressions P 71.

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
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.
Conditional Statements Introduction to Computing Science and Programming I.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Python November 14, Unit 7. Python Hello world, in class.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
Introduction to scripting
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.
Chapter 18: Modifying SAS Data Sets and Tracking Changes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
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.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
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.
Input, Output, and Processing
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
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.
Variables, Expressions and Statements
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
FOR MONDAY: Be prepared to hand in a one-page summary of the data you are going to use for your project and your questions to be addressed in the project.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
CECS 5020 Computers in Education Visual Basic Variables and Constants.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Fundamental Programming Fundamental Programming More Expressions and Data Types.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
THE DOUBLE VARIABLE The double variable can hold very large (or small) numbers. The maximum and minimum values are 17 followed by 307 zero’s.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
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.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Discussion 4 eecs 183 Hannah Westra.
Topics Designing a Program Input, Processing, and Output
Chapter 5: Passing and Processing Macro Parameters
Intro to C Tutorial 4: Arithmetic and Logical expressions
Two “identical” programs
Introduction to the C Language
Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables,
Conditions and Ifs BIS1523 – Lecture 8.
Learning Outcomes –Lesson 4
Macro Variable’s scope
Selection Statements.
Variables, Data Types & Math
How Best to Use Macro Quoting Functions?
Topics Designing a Program Input, Processing, and Output
Relational Operators.
Topics Designing a Program Input, Processing, and Output
Variables, Data Types & Math
Presentation transcript:

Session 7, Chapter 6 From SAS 9.3 Macro Language Reference Macro Expressions P 71

&Eval - p %let A=2; %let B=5; %let operator=+; %put The result of &A &operator &B is %eval(&A &operator &B).; The result of is 7.

Macro Language Operators – p 73 Table 6.3 P 73 ** + - -^~ etc

The macro facility is a string handling facility – p * Use %EVAL in a %LET statement; %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; ******** Note answers are all integer;

%SYSEVAL p. 75 * USE SYSEVAL INSTEAD; %let a=%sysevalf(10.0*3.0); %let b=%sysevalf( ); %let c=%sysevalf(5/3); %put 10.0*3.0 = &a; %put = &b; %put 5/3 = &c; * Note answers can be floating point now. ;

How Macro Evaluates Logical Expression p 76 %macro compnum(first,second); %if &first>&second %then %put &first is greater than &second; %else %if &first=&second %then %put &first equals &second; %else %put &first is less than &second; %mend compnum; *Invoke the COMPNUM macro with these values; %compnum(1,2) %compnum(-1,0) ; The following results are displayed in the log: 1 is less than 2 -1 is less than 0

Other comparisons Floating point p – Type in the code on top of 77 & test Compare character operands in logical expressions p 77 – Type in example code middle of p 77 & test

Chapter 7 – Macro Quoting – p 79 Why doesn’t this work? P 81 %let print=proc print; run;; Why does this work? %let print=%str(proc print; run;); What does %str() do?

NRSTR%() - P 88 Use NRSTR%() when there is a macro variable name in the expression that you don’t want evaluated – this prevents the macro variable from being evaluated %macro example; %local myvar; %let myvar=abc; %put %nrstr(The string &myvar appears in log output,); %put instead of the variable value.; %mend example; %example The string &myvar appears in log output, instead of the variable value.

Example 2 %NRSTR Type in example middle of p 88 %macro credits(d=%nrstr(Mary&Stacy&Joan Ltd.)); footnote "Designed by &d"; %mend credits; Run with %credits() Observe output. What happens if you use %SRT instead? Try it.

BQuote p 89 Use BQUOTE() when an expression has unmatching quotes such as Jones’s NRBQUOTE() when there is a macro expression you don’t want evaluated + unmatching quotes.

Example BQUOTE – p 90 ** Example BQWUOTE p 90; data test; store="Susan's Office Supplies"; call symput('s',store); run; %macro readit; %if %bquote(&s) ne %then %put *** valid ***; %else %put *** null value ***; %mend readit; %readit ; * Observe output in log – what if you don’t use BQUOTE?;

SuperQ – p 92 ***********EXAMPLE SUPERQ ********AND %WINDOW; * It masks items that might require macro quoting; %window ask 'Enter two values:' val 15 attr=underline; %macro a; %put *** This is a. ***; %mend a; %macro test; %display ask; %put *** %superq(val) ***; /* Note absence of ampersand */ %mend test; *invoke the macro TEST; %test

Ch 9, 10 & 11 Ch 9 - Storing and Reusing Macros – read on your own Ch 10 – Macro Errors – Note bullets on p 121 – See Note bottom p 129 double and single quotes Ch 11 – Writing Efficient Code - read on your own

Ch 12 – Macro Language Elements Review Table 12.1 p 156 Table 12.2 p 157 Table 12.3 p 158 Table 12.4 p 159 Table 12.5 p 160 Table 12.9 p 166

End