SAS Certification Handout #11: Adv. Prog. Ch. 9-10

Size: px
Start display at page:

Download "SAS Certification Handout #11: Adv. Prog. Ch. 9-10"

Transcription

1 SAS Certification Handout #11: Adv. Prog. Ch /************ Ch. 9 ********************/ /* SAS Macros -- like writing your own functions in SAS; especially useful for reproducing analyses or reports for new data Macro keys to remember: * %xyz calls macro named "xyz" * &abc is reference to macro variable (inside macro call, or elsewhere in SAS code if &abc is a global variable); Ch. 9 focuses on macro variables */ /* p. 308: automatic macro variables; see these using DICTIONARY table (recall Adv. Ch. 8 [end of handout #10] */ describe table dictionary.macros; create table DICTIONARY.MACROS ( scope char(32) label='macro Scope', name char(32) label='macro Variable Name', offset num label='offset into Macro Variable', value char(200) label='macro Variable Value' ); /* See [and use in simple title statements] a few automatic macro variables */ title1 "Report created &SYSDAY, &SYSDATE9"; title2 'in ' &_CLIENTAPP', running SAS Version' &SYSVER; footnote1 'Note that single quotes do not process macro variable names: &SYSDAY'; select scope, name, offset, value from dictionary.macros where name in ('SYSDATE9','SYSDAY','SYSVER','_CLIENTAPP'); title1; footnote1; Report created Monday, 16FEB2015 in &_CLIENTAPP, running SAS Version 9.4 Macro Scope Macro Variable Name Offset into Macro Variable Macro Variable Value AUTOMATIC SYSDATE9 AUTOMATIC SYSDAY 0 16FEB Monday AUTOMATIC SYSVER Note that single quotes do not process macro variable names: &SYSDAY 1

2 /* %LET creates user-defined macro variables, which are always string variables, even if entered as numeric (p. 310) */ %LET HOnum=11; /* Make example data -- same as Handouts #9 and #10. In SAS Studio, after creating SAS_Cert folder with username jrstevens: */ libname cert '/home/jrstevens/sas_cert'; data cert.sales&honum; format LastName $9. Sales dollar8.; input LastName $ EmplID Division $ Sales; cards; Smith 315 A Nelson 333 A Uribe 612 C Larson 331 B Larsen 216 B Rasmussen 217 A Knecht 861 B D'Angelou 772 A Larson 331 C ; /* pp : How SAS processes macro variables: 1. Tokens [p. 314; like word units] make up SAS statements. 2. Statements are sent to the compiler until SAS hits a step Boundary (like RUN), when the code in the compiler is executed. Macro variable references are processed in step 1 here. Use SYMBOLGEN or %PUT (pp ) to see (in LOG) what macro variable values are used (for debugging, maybe) */ %let minsales = ; options symbolgen; select lastname, sales from cert.sales&honum where sales > &minsales; options nosymbolgen; LastName Sales Uribe $867,159 Knecht $983,152 NOTE: The data set CERT.SALES11 has 9 observations and 4 variables select lastname, sales 63 from cert.sales&honum SYMBOLGEN: Macro variable HONUM resolves to where sales SYMBOLGEN: Macro variable MINSALES resolves to ! > &minsales; 65 2

3 data work.temp; set cert.sales&honum; if sales > &minsales; %PUT 'Macro variable &minsales has value' &minsales; 58 data work.temp; set cert.sales&honum; 59 if sales > &minsales; 60 %PUT 'Macro variable &minsales has value' &minsales; 'Macro variable &minsales has value' /* What if you need to allow special characters (like ' ; & % * /, ) in macro variable value? (Need to prevent compiler from treating these like operators or checks, so they need to be masked; often you can just be careful with double-quotes instead.) pp : %STR < %NRSTR [handles & and %] < %BQUOTE [performs during execution] */ %let reptitle = "Company's biggest sellers; sales above &minsales"; title1 "&reptitle"; /* In SAS Studio, this gives a weird long title; in desktop SAS, it sees "" in title1 and chokes */ 'Companys biggest sellers; sales above ""; OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;ODS HTML CLOSE;&GRAPHTERM; ;* 1 Uribe $867, C 2 Knecht $983, B title1 &reptitle; Company's biggest sellers; sales above Uribe $867, C 2 Knecht $983, B %let reptitle = Company''s biggest sellers; sales above &minsales; /* ERROR in LOG after first semicolon */ %let reptitle = "Company''s biggest sellers; sales above &minsales"; title1 &reptitle; Company''s biggest sellers; sales above Uribe $867, C 2 Knecht $983, B 3

4 /* %STR needs % before tokens that typically appear in pairs */ %let reptitle = %str(company%'s biggest sellers; sales above &minsales); title1 "&reptitle"; Company's biggest sellers; sales above Uribe $867, C 2 Knecht $983, B title1 &reptitle; /* ERROR in LOG after first semicolon (from TITLE1 statement) */ /* Character macro functions (pp ); similar to functions seen previously in Base Ch. 13, but more flexible */ /* %UPCASE */ %let checkval = c; where division="&checkval"; NOTE: There were 0 observations read from the data set CERT.SALES11. WHERE division='c'; where division="%upcase(&checkval)"; 3 Uribe $867, C 9 Larson $381, C /* Note what happens here without quotes: */ where division=%upcase(&checkval); ERROR: Variable C is not on file CERT.SALES11. /* %QUPCASE: allows special characters */ %let checkval = %str(d%'angelou); where upcase(lastname) = "%qupcase(&checkval)"; 8 D'Angelou $332, A /* Other character manipulation macros: %SUBSTR & %QSUBSTR, %INDEX, %SCAN & %QSCAN */ 4

5 /* pp : %SYSFUNC < %QSYSFUNC to call other SAS functions where they normally wouldn't work (like in title) */; where division="c"; title1 "This report created today()."; proc print data=cert.sales&honum; where division="c"; title1 "This report created %SYSFUNC(today())"; where division="c"; title1 "This report created %SYSFUNC(today(),worddate.)"; This report created today(). 3 Uribe $867, C 9 Larson $381, C This report created Uribe $867, C 9 Larson $381, C This report created February 16, Uribe $867, C 9 Larson $381, C /* pp : Can reference macro variable (&abc) right after anything, but may need period (&abc.) if want to reference right before something */ %let year=2; %let std=1; data temp; set cert.sales&honum; minys11 = ; minys21 = ; minys12 = ; minys22 = ; if sales > minys&year&std; var lastname sales; Obs LastName Sales 1 Uribe $867,159 2 Knecht $983,152 %let mink = 5; var lastname sales; where sales > &mink.00000; Obs LastName Sales 1 Smith $553,312 2 Nelson $555,827 3 Uribe $867,159 4 Larson $521,592 7 Knecht $983,152 5

6 /************ Ch. 10 ********************/ /* pp : All macro language is executed before DATA step language, so to correctly define macro variable inside DATA step, need to use CALL SYMPUT('varname',value) [pp ] -or- CALL SYMPUTX [pp ] to remove leading & trailing blanks -and maybe- PUT [pp ] to control conversion of num to char */ %let msg = "sample size less than 5"; %let happened = 0; %let charhap = never; data temp; set cert.sales&honum; if _n_ > 5 then do; CALL SYMPUT('msg',"sample size greater than 5"); call symput('happened',%sysfunc(today())); call symput('charhap',put(%sysfunc(today()),worddate.)); end; var lastname sales; title1 "MSG: &msg"; title2 "HAPPENED: &happened ; CHARHAP: &CharHap"; MSG: sample size greater than 5 HAPPENED: ; CHARHAP: February 16, 2015 Obs LastName Sales 1 Smith $553,312 2 Nelson $555,827 3 Uribe $867,159 4 Larson $521,592 5 Larsen $123,513 6 Rasmussen $125,321 7 Knecht $983,152 8 D'Angelou $332,512 9 Larson $381,592 6

7 /* pp : CALL SYMPUT(varname1, varname2) [no quotes!] in DATA _NULL_ to simultaneously define many macro variables (names in varname1, with values in varname2) */ data temp; input v1 $ v2 $; cards; A 53 B Utah A: 53, B: Utah, C: Cal C Cal ; Obs v1 v2 data _null_; set temp; 1 A 53 call symput(v1, v2); 2 B Utah title1 "A: &A, B: &B, C: &C"; 3 C Cal /* pp : reference macro variable indirectly using && (usually for nested macro references; when code has && in it, it is re-scanned after processing all macro variables, with && re-scanned as &) */ %let minyear1=500000; %let minyear2=700000; %let year=1; data temp; set cert.sales&honum; if sales > &&minyear&year; /* First scan: &year processed as 1 Second scan: &&minyear1 processed as &minyear1 Third scan: &minyear1 processed as */ /* pp : SYMGET('varname') will return value of macro variable within DATA step or SQL call (p. 378); this is useful when the value to be used depends on the value of another variable (depending on row) */ %let Astate = Utah; %let Bstate = Colorado; %let Cstate = California; data temp; set cert.sales&honum; format state $10.; state = symget(left(right(division) 'state')); /* NOTE: need left() and right() to handle trailing blanks */ var lastname division state; title1; NOTE: There were 9 observations read from the data set CERT.SALES11. NOTE: The data set WORK.TEMP has 5 observations and 4 variables. Obs LastName Division state 1 Smith A Utah 2 Nelson A Utah 3 Uribe C California 4 Larson B Colorado 5 Larsen B Colorado 6 Rasmussen A Utah 7 Knecht B Colorado 8 D'Angelou A Utah 9 Larson C California 7

8 /* pp : SELECT... INTO : [need colon!] to create macro variables in PROC SQL. p. 375: &SQLOBS automatic macro variable (#rows in resulting table) */ select division, avg(sales) format dollar12.2 label='division Average', count(sales) label="division Size" into :div1-:div3, :divavg1-:divavg3, :divn1-:divn3 from cert.sales&honum group by division; %let numdiv = &SQLOBS; Division Division Average Division Size A $391, B $542, C $624, select name, value from dictionary.macros where name contains 'DIV'; /* NOTE: SAS treats all macro names as all-uppercase */ Macro Variable Name Macro Variable Value DIV1 A DIV2 B DIV3 C DIVAVG1 $391, DIVAVG2 $542, DIVAVG3 $624, DIVN1 4 DIVN2 3 DIVN3 2 NUMDIV 3 /* p. 377: SEPARATED BY in SQL will concatenate all values in column to a single macro variable */ select distinct division into :alldivs separated by '~' from cert.sales&honum; select name, value from dictionary.macros where name="alldivs"; Macro Variable Name Macro Variable Value ALLDIVS A~B~C 8

9 /* p. 379: use INPUT to convert character value of macro to numeric (for checking equality, for example) */ %let check="315"; where emplid=&check; ERROR: WHERE clause operator requires compatible variables. where emplid=input(&check,3.); 1 Smith $553, A /* pp : SCL (not used elsewhere in Certification training) */ From SAS documentation: "SAS Component Language (SCL) is a programming language designed to facilitate the development of interactive applications using the SAS System. For example, you can use SCL with other SAS software to create data entry applications, to display tables and menus, and to generate and submit SAS source code." SYMPUT & SYMGET can be used to define and retrieve macro variable values (as characters) as in non-scl code. SCL code also allows SYMPUTN & SYMGETN to define and retrieve numeric macro variable values. 9

SAS Certification Handout #10: Adv. Prog. Ch. 5-8

SAS Certification Handout #10: Adv. Prog. Ch. 5-8 SAS Certification Handout #10: Adv. Prog. Ch. 5-8 /************ Ch. 5 ******************* /* First, make example data -- same as Handout #9 libname cert 'C:/jrstevens/Teaching/SAS_Cert/AdvNotes'; /* In

More information

SAS Certification Handout #9: Adv. Prog. Ch. 3-4

SAS Certification Handout #9: Adv. Prog. Ch. 3-4 SAS Certification Handout #9: Adv. Prog. Ch. 3-4 /************ Ch. 3 ********************/ /* First, make example data -- similar to Handout #8 */ libname cert 'C:/jrstevens/Teaching/SAS_Cert/AdvNotes';

More information

SAS Certification Handout #8: Adv. Prog. Ch. 1-2

SAS Certification Handout #8: Adv. Prog. Ch. 1-2 /* First, make example data SAS Certification Handout #8: Adv. Prog. Ch. 1-2 libname cert 'C:/jrstevens/Teaching/SAS_Cert/AdvNotes' /* In SAS Studio, after creating SAS_Cert folder with username jrstevens:

More information

Acknowledgments xi Preface xiii About the Author xv About This Book xvii New in the Macro Language xxi

Acknowledgments xi Preface xiii About the Author xv About This Book xvii New in the Macro Language xxi Contents Part 1 Acknowledgments xi Preface xiii About the Author xv About This Book xvii New in the Macro Language xxi Macro Basics Chapter 1 Introduction 3 1.1 Macro Facility Overview 3 1.2 Terminology

More information

SAS Macro. SAS Training Courses. Amadeus Software Ltd

SAS Macro. SAS Training Courses. Amadeus Software Ltd SAS Macro SAS Training Courses By Amadeus Software Ltd AMADEUS SOFTWARE LIMITED SAS TRAINING Amadeus have been delivering SAS Training since 1989 and our aim is to provide you with best quality SAS training

More information

SAS Macro Language: Reference

SAS Macro Language: Reference SAS Macro Language: Reference INTRODUCTION Getting Started with the Macro Facility This is the macro facility language reference for the SAS System. It is a reference for the SAS macro language processor

More information

Base and Advance SAS

Base and Advance SAS Base and Advance SAS BASE SAS INTRODUCTION An Overview of the SAS System SAS Tasks Output produced by the SAS System SAS Tools (SAS Program - Data step and Proc step) A sample SAS program Exploring SAS

More information

DSCI 325: Handout 15 Introduction to SAS Macro Programming Spring 2017

DSCI 325: Handout 15 Introduction to SAS Macro Programming Spring 2017 DSCI 325: Handout 15 Introduction to SAS Macro Programming Spring 2017 The Basics of the SAS Macro Facility Macros are used to make SAS code more flexible and efficient. Essentially, the macro facility

More information

Introduction to the SAS Macro Facility

Introduction to the SAS Macro Facility Introduction to the SAS Macro Facility Uses for SAS Macros The macro language allows for programs that are dynamic capable of selfmodification. The major components of the macro language include: Macro

More information

Introduction. Getting Started with the Macro Facility CHAPTER 1

Introduction. Getting Started with the Macro Facility CHAPTER 1 1 CHAPTER 1 Introduction Getting Started with the Macro Facility 1 Replacing Text Strings Using Macro Variables 2 Generating SAS Code Using Macros 3 Inserting Comments in Macros 4 Macro Definition Containing

More information

Advanced Macro Topics Steven First, Systems Seminar Consultants, Madison, WI

Advanced Macro Topics Steven First, Systems Seminar Consultants, Madison, WI Paper 19-26 Advanced Macro Topics Steven First, Systems Seminar Consultants, Madison, WI Abstract The SAS macro language continues to be an integral part of the SAS system, and can be a wonderful tool

More information

Basic Macro Processing Prepared by Destiny Corporation

Basic Macro Processing Prepared by Destiny Corporation Basic Macro Processing Prepared by Destiny Corporation Macro variables In this module we discuss the first of the two special characters - the ampersand (&). When the SAS Supervisor sees an ampersand followed

More information

CHAPTER 7 Using Other SAS Software Products

CHAPTER 7 Using Other SAS Software Products 77 CHAPTER 7 Using Other SAS Software Products Introduction 77 Using SAS DATA Step Features in SCL 78 Statements 78 Functions 79 Variables 79 Numeric Variables 79 Character Variables 79 Expressions 80

More information

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools LeRoy Bessler PhD Bessler Consulting and Research Strong Smart Systems Mequon, WI, USA Le_Roy_Bessler@wi.rr.com

More information

Using Macro Functions

Using Macro Functions Using Macro Functions Arthur L. Carpenter California Occidental Consultants ABSTRACT Many macro functions are very analogous to those of the DATA step. The differences are in how they are used and applied.

More information

SAS CURRICULUM. BASE SAS Introduction

SAS CURRICULUM. BASE SAS Introduction SAS CURRICULUM BASE SAS Introduction Data Warehousing Concepts What is a Data Warehouse? What is a Data Mart? What is the difference between Relational Databases and the Data in Data Warehouse (OLTP versus

More information

MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL

MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL ABSTRACT: Have you ever been faced with this scenario? It s your first day on the

More information

From Carpenter's Complete Guide to the SAS Macro Language, Third Edition. Full book available for purchase here.

From Carpenter's Complete Guide to the SAS Macro Language, Third Edition. Full book available for purchase here. From Carpenter's Complete Guide to the SAS Macro Language, Third Edition. Full book available for purchase here. Contents Acknowledgments... xiii About This Book... xv About The Author... xviii Part 1:

More information

Tired of CALL EXECUTE? Try DOSUBL

Tired of CALL EXECUTE? Try DOSUBL ABSTRACT SESUG Paper BB-132-2017 Tired of CALL EXECUTE? Try DOSUBL Jueru Fan, PPD, Morrisville, NC DOSUBL was first introduced as a function in SAS V9.3. It enables the immediate execution of SAS code

More information

SAS TM Macro Basics and Fundamentals Timothy J Harrington, Trilogy Consulting Corporation, Waukegan, IL

SAS TM Macro Basics and Fundamentals Timothy J Harrington, Trilogy Consulting Corporation, Waukegan, IL SAS TM Macro Basics and Fundamentals Timothy J Harrington, Trilogy Consulting Corporation, Waukegan, IL Abstract This paper introduces and discusses the SAS MACRO language for new SAS Programmers, or those

More information

More About SAS Macros

More About SAS Macros More About SAS Macros (Than You Thought Possible) Donald P. Gallogly DCBS IMD Topics The SAS Macros System Macro Variables Writing Macros The SAS Macros System The SAS Macros System SAS macros and macro

More information

Sandra Hendren Health Data Institute

Sandra Hendren Health Data Institute INTRODUCTION TO THE MACRO LANGUAGE Sandra Hendren Health Data Institute The purpose of this paper is to explain the macro language at a conceptual level. It will not discuss the syntax of the language

More information

Arthur L. Carpenter California Occidental Consultants, Oceanside, California

Arthur L. Carpenter California Occidental Consultants, Oceanside, California Paper 028-30 Storing and Using a List of Values in a Macro Variable Arthur L. Carpenter California Occidental Consultants, Oceanside, California ABSTRACT When using the macro language it is not at all

More information

Program Validation: Logging the Log

Program Validation: Logging the Log Program Validation: Logging the Log Adel Fahmy, Symbiance Inc., Princeton, NJ ABSTRACT Program Validation includes checking both program Log and Logic. The program Log should be clear of any system Error/Warning

More information

An Introduction to SAS Macros

An Introduction to SAS Macros An Introduction to SAS Macros Expanded token SAS Program (Input Stack) SAS Wordscanner (Tokenization) Non-Macro (Tokens) SAS Compiler % and & Triggers Macro Facility Steven First, President 2997 Yarmouth

More information

Journey to the center of the earth Deep understanding of SAS language processing mechanism Di Chen, SAS Beijing R&D, Beijing, China

Journey to the center of the earth Deep understanding of SAS language processing mechanism Di Chen, SAS Beijing R&D, Beijing, China Journey to the center of the earth Deep understanding of SAS language processing Di Chen, SAS Beijing R&D, Beijing, China ABSTRACT SAS is a highly flexible and extensible programming language, and a rich

More information

Understanding the Concepts and Features of Macro Programming 1

Understanding the Concepts and Features of Macro Programming 1 Contents Preface ix Acknowledgments xi Part 1 Understanding the Concepts and Features of Macro Programming 1 Chapter 1 Introduction 3 What Is the SAS Macro Facility? 4 What Are the Advantages of the SAS

More information

Contents. About This Book...1

Contents. About This Book...1 Contents About This Book...1 Chapter 1: Basic Concepts...5 Overview...6 SAS Programs...7 SAS Libraries...13 Referencing SAS Files...15 SAS Data Sets...18 Variable Attributes...21 Summary...26 Practice...28

More information

Going Under the Hood: How Does the Macro Processor Really Work?

Going Under the Hood: How Does the Macro Processor Really Work? Going Under the Hood: How Does the Really Work? ABSTRACT Lisa Lyons, PPD, Inc Hamilton, NJ Did you ever wonder what really goes on behind the scenes of the macro processor, or how it works with other parts

More information

title1 "Visits at &string1"; proc print data=hospitalvisits; where sitecode="&string1";

title1 Visits at &string1; proc print data=hospitalvisits; where sitecode=&string1; PharmaSUG 2012 Paper TF01 Macro Quoting to the Rescue: Passing Special Characters Mary F. O. Rosenbloom, Edwards Lifesciences LLC, Irvine, CA Art Carpenter, California Occidental Consultants, Anchorage,

More information

Submitting SAS Code On The Side

Submitting SAS Code On The Side ABSTRACT PharmaSUG 2013 - Paper AD24-SAS Submitting SAS Code On The Side Rick Langston, SAS Institute Inc., Cary NC This paper explains the new DOSUBL function and how it can submit SAS code to run "on

More information

A Time Saver for All: A SAS Toolbox Philip Jou, Baylor University, Waco, TX

A Time Saver for All: A SAS Toolbox Philip Jou, Baylor University, Waco, TX South Central SAS Users Group 2016 A Time Saver for All: A SAS Toolbox Philip Jou, Baylor University, Waco, TX ABSTRACT SAS Macros are a useful tool to any SAS Programmer. A macro variable can be used

More information

Run your reports through that last loop to standardize the presentation attributes

Run your reports through that last loop to standardize the presentation attributes PharmaSUG2011 - Paper TT14 Run your reports through that last loop to standardize the presentation attributes Niraj J. Pandya, Element Technologies Inc., NJ ABSTRACT Post Processing of the report could

More information

The Ins and Outs of %IF

The Ins and Outs of %IF Paper 1135-2017 The Ins and Outs of %IF M. Michelle Buchecker, ThotWave Technologies, LLC. ABSTRACT Have you ever had your macro code not work and you couldn't figure out why? Even something as simple

More information

An Introduction to SAS Macros Steven First, Systems Seminar Consultants, Madison, WI

An Introduction to SAS Macros Steven First, Systems Seminar Consultants, Madison, WI Paper 153-26 An Introduction to SAS Macros Steven First, Systems Seminar Consultants, Madison, WI Abstract The SAS programming language has a rich tool-box of features that can offer a lot of power to

More information

Macro Internals for the User Developer s Overview. Susan O Connor, SAS Institute Inc., Cary, NC

Macro Internals for the User Developer s Overview. Susan O Connor, SAS Institute Inc., Cary, NC Macro Internals for the User Developer s Overview Susan O Connor, SAS Institute Inc., Cary, NC ABSTRACT You have used the macro language software that is part of base software from SAS Institute Inc. or

More information

AN INTRODUCTION TO MACRO VARIABLES AND MACRO PROGRAMS Mike Zdeb, School of Public Health

AN INTRODUCTION TO MACRO VARIABLES AND MACRO PROGRAMS Mike Zdeb, School of Public Health AN INTRODUCTION TO MACRO VARIABLES AND MACRO PROGRAMS Mike Zdeb, University@Albany School of Public Health INTRODUCTION There are a number of SAS tools that you may never have to use. Why? The main reason

More information

Surviving the SAS Macro Jungle by Using Your Own Programming Toolkit Kevin Russell, SAS Institute Inc., Cary, North Carolina

Surviving the SAS Macro Jungle by Using Your Own Programming Toolkit Kevin Russell, SAS Institute Inc., Cary, North Carolina PharmaSUG 2016 Paper BB11 Surviving the SAS Macro Jungle by Using Your Own Programming Toolkit Kevin Russell, SAS Institute Inc., Cary, North Carolina ABSTRACT Almost every night there is a reality show

More information

Make Your Life a Little Easier: A Collection of SAS Macro Utilities. Pete Lund, Northwest Crime and Social Research, Olympia, WA

Make Your Life a Little Easier: A Collection of SAS Macro Utilities. Pete Lund, Northwest Crime and Social Research, Olympia, WA Make Your Life a Little Easier: A Collection of SAS Macro Utilities Pete Lund, Northwest Crime and Social Research, Olympia, WA ABSTRACT SAS Macros are used in a variety of ways: to automate the generation

More information

Taming a Spreadsheet Importation Monster

Taming a Spreadsheet Importation Monster SESUG 2013 Paper BtB-10 Taming a Spreadsheet Importation Monster Nat Wooding, J. Sargeant Reynolds Community College ABSTRACT As many programmers have learned to their chagrin, it can be easy to read Excel

More information

SURVIVING THE SAS MACRO JUNGLE BY USING YOUR OWN PROGRAMMING TOOLKIT

SURVIVING THE SAS MACRO JUNGLE BY USING YOUR OWN PROGRAMMING TOOLKIT PharmaSUG 2016 Paper BB11 SURVIVING THE SAS MACRO JUNGLE BY USING YOUR OWN PROGRAMMING TOOLKIT KEVIN RUSSELL Photo credit: Geoff Gallice / CC by 2.0 TOOLS FOR YOUR MACRO PROGRAMMING TOOLKIT The DOSUBL

More information

Logging the Log Magic: Pulling the Rabbit out of the Hat

Logging the Log Magic: Pulling the Rabbit out of the Hat ABSTRACT PharmaSUG2010 - Paper TT08 Logging the Log Magic: Pulling the Rabbit out of the Hat Adel Fahmy, BenchWorkzz, Austin, Texas Program Validation includes checking both program Log and Logic. Program

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Efficiency Programming with Macro Variable Arrays

Efficiency Programming with Macro Variable Arrays ABSTRACT MWSUG 2018 - Paper SP-062 Efficiency Programming with Macro Variable Arrays Veronica Renauldo, QST Consultations, LTD, Allendale, MI Macros in themselves boost productivity and cut down on user

More information

GET A GRIP ON MACROS IN JUST 50 MINUTES! Arthur Li, City of Hope Comprehensive Cancer Center, Duarte, CA

GET A GRIP ON MACROS IN JUST 50 MINUTES! Arthur Li, City of Hope Comprehensive Cancer Center, Duarte, CA GET A GRIP ON MACROS IN JUST 50 MINUTES! Arthur Li, City of Hope Comprehensive Cancer Center, Duarte, CA ABSTRACT The SAS macro facility, which includes macro variables and macro programs, is the most

More information

What Is SAS? CHAPTER 1 Essential Concepts of Base SAS Software

What Is SAS? CHAPTER 1 Essential Concepts of Base SAS Software 3 CHAPTER 1 Essential Concepts of Base SAS Software What Is SAS? 3 Overview of Base SAS Software 4 Components of the SAS Language 4 SAS Files 4 SAS Data Sets 5 External Files 5 Database Management System

More information

Macro Bugs - How to Create, Avoid and Destroy Them Ian Whitlock, Kennett Square, PA

Macro Bugs - How to Create, Avoid and Destroy Them Ian Whitlock, Kennett Square, PA Paper TU-13 Macro Bugs - How to Create, Avoid and Destroy Them Ian Whitlock, Kennett Square, PA ABSTRACT The central theme of this paper is the macro debugging process. However, a great many bugs are simply

More information

Macro Language Dictionary

Macro Language Dictionary 3 CHAPTER 1 Macro Language Dictionary Dictionary 3 Dictionary %BQUOTE and %NRBQUOTE Mask special characters and mnemonic operators in a resolved value at macro execution Type: Macro quoting functions See

More information

Procedure for Stamping Source File Information on SAS Output Elizabeth Molloy & Breda O'Connor, ICON Clinical Research

Procedure for Stamping Source File Information on SAS Output Elizabeth Molloy & Breda O'Connor, ICON Clinical Research Procedure for Stamping Source File Information on SAS Output Elizabeth Molloy & Breda O'Connor, ICON Clinical Research ABSTRACT In the course of producing a report for a clinical trial numerous drafts

More information

Sample Questions. SAS Advanced Programming for SAS 9. Question 1. Question 2

Sample Questions. SAS Advanced Programming for SAS 9. Question 1. Question 2 Sample Questions The following sample questions are not inclusive and do not necessarily represent all of the types of questions that comprise the exams. The questions are not designed to assess an individual's

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

Top-Down Programming with SAS Macros Edward Heaton, Westat, Rockville, MD

Top-Down Programming with SAS Macros Edward Heaton, Westat, Rockville, MD Paper P813 Top-Down Programming with SAS Macros Edward Heaton, Westat, Rockville, MD ABSTRACT Structured, top-down programming techniques are not intuitively obvious in the SAS language, but macros can

More information

Hidden in plain sight: my top ten underpublicized enhancements in SAS Versions 9.2 and 9.3

Hidden in plain sight: my top ten underpublicized enhancements in SAS Versions 9.2 and 9.3 Hidden in plain sight: my top ten underpublicized enhancements in SAS Versions 9.2 and 9.3 Bruce Gilsen, Federal Reserve Board, Washington, DC ABSTRACT SAS Versions 9.2 and 9.3 contain many interesting

More information

MACRO VARIABLES IN SAS ENTERPRISE GUIDE Khoi To, Office of Planning and Decision Support, Virginia Commonwealth University

MACRO VARIABLES IN SAS ENTERPRISE GUIDE Khoi To, Office of Planning and Decision Support, Virginia Commonwealth University SAS 5580-2016 MACRO VARIABLES IN SAS ENTERPRISE GUIDE Khoi To, Office of Planning and Decision Support, Virginia Commonwealth University ABSTRACT For SAS Enterprise Guide users, sometimes macro variables

More information

SAS Online Training: Course contents: Agenda:

SAS Online Training: Course contents: Agenda: SAS Online Training: Course contents: Agenda: (1) Base SAS (6) Clinical SAS Online Training with Real time Projects (2) Advance SAS (7) Financial SAS Training Real time Projects (3) SQL (8) CV preparation

More information

Tales from the Help Desk 5: Yet More Solutions for Common SAS Mistakes Bruce Gilsen, Federal Reserve Board

Tales from the Help Desk 5: Yet More Solutions for Common SAS Mistakes Bruce Gilsen, Federal Reserve Board Tales from the Help Desk 5: Yet More Solutions for Common SAS Mistakes Bruce Gilsen, Federal Reserve Board INTRODUCTION In 25 years as a SAS consultant at the Federal Reserve Board, I have seen SAS users

More information

&&&, ;;, and Other Hieroglyphics Advanced Macro Topics Chris Yindra, C. Y. Training Associates

&&&, ;;, and Other Hieroglyphics Advanced Macro Topics Chris Yindra, C. Y. Training Associates &&&, ;;, and Other Hieroglyphics Advanced Macro Topics Chris Yindra, C. Y. Training Associates INTRODUCTION SAS macros are powerful tools that can create reusable code modules to do a variety of programming

More information

/* SAS Macro UNISTATS Version 2.2 December 2017

/* SAS Macro UNISTATS Version 2.2 December 2017 /*-------------------------------------------------------------------- SAS Macro UNISTATS Version 2.2 December 2017 UNISTATS makes PROC UNIVARIATE statistics more convenient by presenting one row for each

More information

I like macros. But sometimes they can be hard to understand.

I like macros. But sometimes they can be hard to understand. Understanding macros I like macros. But sometimes they can be hard to understand. Part of the problem, I think, is that you have to think in two languages at once. You re using the macro language to generate

More information

Foundations and Fundamentals. SAS System Options: The True Heroes of Macro Debugging Kevin Russell and Russ Tyndall, SAS Institute Inc.

Foundations and Fundamentals. SAS System Options: The True Heroes of Macro Debugging Kevin Russell and Russ Tyndall, SAS Institute Inc. SAS System Options: The True Heroes of Macro Debugging Kevin Russell and Russ Tyndall, SAS Institute Inc., Cary, NC ABSTRACT It is not uncommon for the first draft of any macro application to contain errors.

More information

STAT:5400 Computing in Statistics. Other software packages. Microsoft Excel spreadsheet very convenient for entering data in flatfile

STAT:5400 Computing in Statistics. Other software packages. Microsoft Excel spreadsheet very convenient for entering data in flatfile STAT:5400 Computing in Statistics Other Software Packages Proc import A bit on SAS macro language Lecture 26 ov 2, 2016 Kate Cowles 374 SH, 335-0727 kate-cowles@uiowaedu Other software packages Microsoft

More information

Dequote me on that: Using the dequote function to add some friendliness to SAS macros

Dequote me on that: Using the dequote function to add some friendliness to SAS macros Paper CC02 Dequote me on that: Using the dequote function to add some friendliness to SAS macros John Hendrickx, Danone Nutricia Research, Utrecht, The Netherlands ABSTRACT SAS macros need to be user-friendly

More information

An Animated Guide: An Introduction to SAS Macro Quoting Russ Lavery Bryn Mawr, PA

An Animated Guide: An Introduction to SAS Macro Quoting Russ Lavery Bryn Mawr, PA An Animated Guide: An Introduction to SAS Macro Quoting Russ Lavery Bryn Mawr, PA Figure 1 ABSTRACT This paper builds on a NESUG 2002 paper that described the general functioning of the SAS Macro Processor.

More information

SAS Macro Programming for Beginners

SAS Macro Programming for Beginners ABSTRACT SAS Macro Programming for Beginners Lora D. Delwiche, Winters, CA Susan J. Slaughter, Avocet Solutions, Davis, CA Macro programming is generally considered an advanced topic. But, while macros

More information

SAS Macro Language 1: Essentials. Course Notes

SAS Macro Language 1: Essentials. Course Notes SAS Macro Language 1: Essentials Course Notes SAS Macro Language 1: Essentials Course Notes was developed by Jim Simon and Linda Mitterling. Additional contributions were made by Davetta Dunlap, John McCall,

More information

STATION

STATION ------------------------------STATION 1------------------------------ 1. Which of the following statements displays all user-defined macro variables in the SAS log? a) %put user=; b) %put user; c) %put

More information

Paper HOW-06. Tricia Aanderud, And Data Inc, Raleigh, NC

Paper HOW-06. Tricia Aanderud, And Data Inc, Raleigh, NC Paper HOW-06 Building Your First SAS Stored Process Tricia Aanderud, And Data Inc, Raleigh, NC ABSTRACT Learn how to convert a simple SAS macro into three different stored processes! Using examples from

More information

Jeff Phillips, ARC Professional Services Group Veronica Walgamotte, ARC Professional Services Group Derek Drummond, ARC Professional Services Group

Jeff Phillips, ARC Professional Services Group Veronica Walgamotte, ARC Professional Services Group Derek Drummond, ARC Professional Services Group ~- WARNING: ApPARENT MACRO INVOCATION NOT RESOLVED TECHNIQUES FOR DEBUGGING MACRO CODE Jeff Phillips, ARC Professional Services Group Veronica Walgamotte, ARC Professional Services Group Derek Drummond,

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on: Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

More information

Unlock SAS Code Automation with the Power of Macros

Unlock SAS Code Automation with the Power of Macros SESUG 2015 ABSTRACT Paper AD-87 Unlock SAS Code Automation with the Power of Macros William Gui Zupko II, Federal Law Enforcement Training Centers SAS code, like any computer programming code, seems to

More information

SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC

SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC PharmaSUG2010 - Paper TT06 SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC ABSTRACT One great leap that beginning and intermediate

More information

/ * %STR(argument) %NRSTR(argument)

/ * %STR(argument) %NRSTR(argument) Macro Quoting Functions Jerry Mock SAS nstitute nc. Quoting Functions Available in the SAS Macro Language Compile time functions %STR(argument) 6NRSTR (argument) Execution time functions %QUOTE (argument)

More information

A Tutorial on the SAS Macro Language

A Tutorial on the SAS Macro Language HW152 SESUG 2015 A Tutorial on the SAS Macro Language John J. Cohen, Advanced Data Concepts LLC, Newark, DE ABSTRACT The SAS Macro language is another language that rests on top of regular SAS code. If

More information

BASICS BEFORE STARTING SAS DATAWAREHOSING Concepts What is ETL ETL Concepts What is OLAP SAS. What is SAS History of SAS Modules available SAS

BASICS BEFORE STARTING SAS DATAWAREHOSING Concepts What is ETL ETL Concepts What is OLAP SAS. What is SAS History of SAS Modules available SAS SAS COURSE CONTENT Course Duration - 40hrs BASICS BEFORE STARTING SAS DATAWAREHOSING Concepts What is ETL ETL Concepts What is OLAP SAS What is SAS History of SAS Modules available SAS GETTING STARTED

More information

Exploring the SAS Macro Function %SYSFUNC

Exploring the SAS Macro Function %SYSFUNC Paper CC11 Exploring the SAS Macro Function %SYSFUNC Lin Yan and Helen Wang Department of Scientific Programming Merck Research Labs, Merck & Co., Inc. Rahway, New Jersey 07065 ABSTRACT The SAS macro function

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

Introduction to SAS Statistical Package

Introduction to SAS Statistical Package Instructor: Introduction to SAS Statistical Package Biostatistics 140.632 Lecture 1 Lucy Meoni lmeoni@jhmi.edu Teaching Assistant : Sorina Eftim seftim@jhsph.edu Lecture/Lab: Room 3017 WEB site: www.biostat.jhsph.edu/bstcourse/bio632/default.htm

More information

SAS 101. Based on Learning SAS by Example: A Programmer s Guide Chapter 21, 22, & 23. By Tasha Chapman, Oregon Health Authority

SAS 101. Based on Learning SAS by Example: A Programmer s Guide Chapter 21, 22, & 23. By Tasha Chapman, Oregon Health Authority SAS 101 Based on Learning SAS by Example: A Programmer s Guide Chapter 21, 22, & 23 By Tasha Chapman, Oregon Health Authority Topics covered All the leftovers! Infile options Missover LRECL=/Pad/Truncover

More information

Merge Processing and Alternate Table Lookup Techniques Prepared by

Merge Processing and Alternate Table Lookup Techniques Prepared by Merge Processing and Alternate Table Lookup Techniques Prepared by The syntax for data step merging is as follows: International SAS Training and Consulting This assumes that the incoming data sets are

More information

work.test temp.test sasuser.test test

work.test temp.test sasuser.test test DSCI 325 Midterm Practice Test Spring 2017 Name: 1. Consider the following four names used to create a SAS data set: work.test temp.test sasuser.test test How many of these will be stored as permanent

More information

An Introduction to SAS/SHARE, By Example

An Introduction to SAS/SHARE, By Example Paper AD01 An Introduction to SAS/SHARE, By Example Larry Altmayer, U.S. Census Bureau, Washington, DC ABSTRACT SAS/SHARE software is a useful tool for allowing several users to access and edit the same

More information

Playing With String Data David Fickbobm, Fireman's Fund Insurance Company, Novato, CA

Playing With String Data David Fickbobm, Fireman's Fund Insurance Company, Novato, CA Playing With String Data David Fickbobm, Fireman's Fund Insurance Company, Novato, CA Abstract This talk will introduce beginning SAS users to the idea of using string functions. Users will be introduced

More information

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS TO SAS NEED FOR SAS WHO USES SAS WHAT IS SAS? OVERVIEW OF BASE SAS SOFTWARE DATA MANAGEMENT FACILITY STRUCTURE OF SAS DATASET SAS PROGRAM PROGRAMMING LANGUAGE ELEMENTS OF THE SAS LANGUAGE RULES FOR SAS

More information

Contents of SAS Programming Techniques

Contents of SAS Programming Techniques Contents of SAS Programming Techniques Chapter 1 About SAS 1.1 Introduction 1.1.1 SAS modules 1.1.2 SAS module classification 1.1.3 SAS features 1.1.4 Three levels of SAS techniques 1.1.5 Chapter goal

More information

SAS Macro Design Issues Ian Whitlock, Westat

SAS Macro Design Issues Ian Whitlock, Westat Paper 67-27 SAS Macro Design Issues Ian Whitlock, Westat Abstract Two questions motivated this paper. The first came more than twenty years ago at the end of my first programming course when the professor

More information

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China PharmaSUG China 2016 - Paper 81 Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China ABSTRACT There are several macro quoting functions in SAS and even some

More information

SAS/FSP 9.2. Procedures Guide

SAS/FSP 9.2. Procedures Guide SAS/FSP 9.2 Procedures Guide The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2008. SAS/FSP 9.2 Procedures Guide. Cary, NC: SAS Institute Inc. SAS/FSP 9.2 Procedures

More information

Learn to Please: Creating SAS Programs for Others

Learn to Please: Creating SAS Programs for Others Paper 0872-2017 Learn to Please: Creating SAS Programs for Others Peter Crawford, Crawford Software Consultancy Limited ABSTRACT Programming for others involves new disciplines not called for when we write

More information

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp.

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp. Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp. ABSTRACT The SAS Macro Facility is a tool which lends flexibility to your SAS code and promotes easier maintenance. It

More information

II (concatenation), INDEX, INDEXC, AND SOUNDEX. Wow, did you realize there were so many string functions? let's get started.

II (concatenation), INDEX, INDEXC, AND SOUNDEX. Wow, did you realize there were so many string functions? let's get started. Having a Ball with Strings Ronald Cody, Ed.D. Robert Wood Johnson Medical School Introduction SAS software is especially rich in its assortment of functions that deal with character data. This class of

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

3. Almost always use system options options compress =yes nocenter; /* mostly use */ options ps=9999 ls=200;

3. Almost always use system options options compress =yes nocenter; /* mostly use */ options ps=9999 ls=200; Randy s SAS hints, updated Feb 6, 2014 1. Always begin your programs with internal documentation. * ***************** * Program =test1, Randy Ellis, first version: March 8, 2013 ***************; 2. Don

More information

The Three I s of SAS Log Messages, IMPORTANT, INTERESTING, and IRRELEVANT William E Benjamin Jr, Owl Computer Consultancy, LLC, Phoenix AZ.

The Three I s of SAS Log Messages, IMPORTANT, INTERESTING, and IRRELEVANT William E Benjamin Jr, Owl Computer Consultancy, LLC, Phoenix AZ. ABSTRACT Paper TT_14 The Three I s of SAS Log Messages, IMPORTANT, INTERESTING, and IRRELEVANT William E Benjamin Jr, Owl Computer Consultancy, LLC, Phoenix AZ. I like to think that SAS error messages

More information

A Second Look at SAS Macro Design Issues Ian Whitlock, Kennett Square, PA

A Second Look at SAS Macro Design Issues Ian Whitlock, Kennett Square, PA Paper 244-29 A Second Look at SAS Macro Design Issues Ian Whitlock, Kennett Square, PA ABSTRACT At SUGI 27 the author presented a paper "SAS Macro Design Issues" as a Beginning Tutorial. The use of names

More information

Your Own SAS Macros Are as Powerful as You Are Ingenious

Your Own SAS Macros Are as Powerful as You Are Ingenious Paper CC166 Your Own SAS Macros Are as Powerful as You Are Ingenious Yinghua Shi, Department Of Treasury, Washington, DC ABSTRACT This article proposes, for user-written SAS macros, separate definitions

More information

Seminar Series: CTSI Presents

Seminar Series: CTSI Presents Biostatistics, Epidemiology & Research Design (BERD) Howard Cabral, PhD, MPH Christine Chaisson, MPH Seminar Series: CTSI Presents November 20, 2014 Demystifying SAS Macros BUSPH Data Coordinating Center

More information

Uncommon Techniques for Common Variables

Uncommon Techniques for Common Variables Paper 11863-2016 Uncommon Techniques for Common Variables Christopher J. Bost, MDRC, New York, NY ABSTRACT If a variable occurs in more than one data set being merged, the last value (from the variable

More information

e. That's accomplished with:

e. That's accomplished with: Make Your Life a Little Easier: A Collection of SAs Macro Utilities Pete Lund, Northwest Crime and Social Research, Olympia, WA ABSTRACT SAs Macros are used in a variety of ways: to automate the generation

More information

A Quick and Gentle Introduction to PROC SQL

A Quick and Gentle Introduction to PROC SQL ABSTRACT Paper B2B 9 A Quick and Gentle Introduction to PROC SQL Shane Rosanbalm, Rho, Inc. Sam Gillett, Rho, Inc. If you are afraid of SQL, it is most likely because you haven t been properly introduced.

More information

Robust Programming Techniques in the SAS System. Alice M. Cheng, Pfizer Inc., New York, New York

Robust Programming Techniques in the SAS System. Alice M. Cheng, Pfizer Inc., New York, New York Robust Programming Techniques in the SAS System Alice M. Cheng, Pfizer Inc., New York, New York Abstract Have you ever had a program that runs on some occasions and fails on others? Has a change in input

More information