1 Jerry Tsai This presentation and code available at: clintuition.com/pubs/

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 The Basics of Javascript Programming the World Wide Web Fourth.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
1 Learning Touchmath *Graphics taken from
Year 6 mental test 5 second questions
ZMQS ZMQS
Haas MFE SAS Workshop Lecture 3:
BT Wholesale October Creating your own telephone network WHOLESALE CALLS LINE ASSOCIATED.
ABC Technology Project
Excel Lesson 11 Improving Data Accuracy
1 University of Utah – School of Computing Computer Science 1021 "Thinking Like a Computer"
© S Haughton more than 3?
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
© Charles van Marrewijk, An Introduction to Geographical Economics Brakman, Garretsen, and Van Marrewijk.
VOORBLAD.
Progam.-(6)* Write a program to Display series of Leaner, Even and odd using by LOOP command and Direct Offset address. Design by : sir Masood.
Identifying Our Own Style Extended DISC ® Personal Analysis.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Squares and Square Root WALK. Solve each problem REVIEW:
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
SIMOCODE-DP Software.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
1 of 31 Images from Africa. 2 of 31 My little Haitian friend Antoine (1985)
Addition 1’s to 20.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Test B, 100 Subtraction Facts
Januar MDMDFSSMDMDFSSS
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Intracellular Compartments and Transport
1 Unit 1 Kinematics Chapter 1 Day
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Essential Cell Biology
How Cells Obtain Energy from Food
Immunobiology: The Immune System in Health & Disease Sixth Edition
Chapter 30 Induction and Inductance In this chapter we will study the following topics: -Faraday’s law of induction -Lenz’s rule -Electric field induced.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Presentation transcript:

1 Jerry Tsai This presentation and code available at: clintuition.com/pubs/

22 Efficiently Handle Lists of Items using the SAS® Macro Language --- Save Time and Reduce Errors Jerry Tsai

3 Problem Statement Working with a data set that contains many variables often requires repeating the same editing task over and over on those variables. Problems with having to make repetitive edits: Increased chance of inconsistency, leading to errors in syntax or in logic Increase in time required for task completion

4 Data Set Examples #1: Laboratory values Variables: hemoglobin, hematocrit, MCH, MCV, RBC, platelets, etc. #2: Survey data Variables: Question 1, Question 2, Question 3, etc.

5 Desired Solution Write code addressing these multiple items with as little unnecessary repetition as possible– and do it correctly the first time.

6 Process Flow Write code that addresses one item on the list and validate that it works as desired. Extend the validated code to all items on the list.

7 Method Edit the validated code for use with a macro: Replace the list item with a wildcard character. With each iteration, this wildcard will be replaced with a item on the list. The macro will iterate through the list using a loop.

8 MACRO %ITERLIST Two parameters: LIST CODE %iterlist(list=, code=)

9 Setup Macro variable containing a space-delimited list, e.g.: %let mylist = alfa bravo charlie...yankee zulu;

10 data new; set old ( rename = ) ; run; Example #1: Renaming a List of Vars (alfa = alfa_n)

11 data new; set old ( rename = ) ; run; Example #1: Renaming a List of Vars (alfa = alfa_n) ? = ?_n Replace item with wildcard character, ?

12 data new; set old ( rename = ) ; run; Example #1: Renaming a List of Vars ? = ?_n) (

13 data new; set old ( rename = ) ; run; Example #1: Renaming a List of Vars ( ? = ?_n )

14 data new; set old ( rename = ) ; run; Example #1: Renaming a List of Vars )) ( ? = ?_n ) %iterlist(list = &mylist., code = %str(

15 data new; set old ( rename = ) ; run; Example #1: Renaming a List of Vars (alfa = alfa_n beta = beta_n... zulu = zulu_n )

16 proc means data = old; var &mylist.; output out = oldstats (drop=_type_ _freq_) ; run; Example #2: PROC MEANS statistics n(alfa )= alfa_nb mean(alfa )= alfa_mn std(alfa )= alfa_sd

17 proc means data = old; var &mylist.; output out = oldstats (drop=_type_ _freq_) ; run; Example #2: PROC MEANS statistics %iterlist(list = &mylist., code = %str( n(?)=?_nb)) %iterlist(list = &mylist., code = %str(mean(?)=?_mn)) %iterlist(list = &mylist., code = %str( std(?)=?_sd))

18 %printem(inputds = old, variabl = alfa); %macro printem(inputds =, variabl =); proc print data=&inputds.; var &variabl. ; run; %mend printem; Example #3: Nested Macro Call

19 %iterlist ( list = &mylist., code = %nrstr( %printem(inputds = old, variabl = ?); ) ); Example #3: Nested Macro Call

20 Advantages of %ITERLIST() Robust approach separates programming logic from the items being iterated over. Save programming time by avoiding needless typing. By retaining the syntax of validated code, reduce the likelihood of error.

21 Noteworthy Aspects of %ITERLIST %DO-%END looping Macro quoting functions, e.g., %STR(), %UNQUOTE() %QSYSFUNC() TRANWRD()

22 Suggested Reading Carpenter, Art. Resolving and Using &&var&i Macro Variables - SUGI 22 Proceedings (1997) Carpenter, Art. Storing and Using a List of Values in a Macro Variable - SUGI 30 Proceedings (2005) Morris, Robert. Text Utility Macros for Manipulating Lists of Variable Names - SUGI 30 Proceedings (2005) Clay, Ted. Tight Looping With Macro Arrays - SUGI 31 Proceedings (2006)

23 Jerry Tsai This presentation and code available at: clintuition.com/pubs/ Questions? Comments?