3 Parameter Validation.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
I OWA S TATE U NIVERSITY Department of Animal Science Writing Flexible Codes with the SAS Macro Facility (Chapter in the 7 Little SAS Book) Animal Science.
SAS SQL SAS Seminar Series
SAS Macros ® 101 How I learned to stop worrying and love macros Alex Chaplin BCS USA Section.
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.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
1 Chapter 5: Macro Programs 5.1 Conditional Processing 5.2 Parameter Validation 5.3 Iterative Processing 5.4 Global and Local Symbol Tables.
1 Chapter 1: Introduction 1.1 Course Logistics 1.2 Purpose of the Macro Facility 1.3 Program Flow.
Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin.
Advanced Spreadsheet Skills for Game Designers
11 Chapter 4: Developing Reusable Macros 4.1 Introduction 4.2 Developing Macro Routines 4.3 Developing Macro Functions.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
1 Using the Magical Keyword “INTO” in PROC SQL Thiru Satchi Blue Cross and Blue Shield of Massachusetts Boston Area SAS Users Group April 5, 1999.
1 Chapter 4: DATA Step and SQL Interfaces 4.1 Creating Macro Variables in the DATA Step 4.2 Indirect References to Macro Variables 4.3 Retrieving Macro.
Tips & Tricks From your fellow SAS users 9/30/2004.
A Macro to Exchange the Values of Arbitrary Cells.
Chapter 7: Macros in SAS  Macros provide for more flexible programming in SAS  Macros make SAS more “object-oriented”, like R 1 © Fall 2011 John Grego.
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.
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
WaveMaker Visual AJAX Studio 4.0 Training Custom Queries.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
1 Cleaning Invalid Data. Clean data by using assignment statements in the DATA step. Clean data by using IF-THEN / ELSE statements in the DATA step. 2.
Session 1 Retrieving Data From a Single Table
Chapter 10: Accessing Relational Databases (Self-Study)
Chapter 5: Passing and Processing Macro Parameters
SAS Macro Language.
Two “identical” programs
Indexer AKEEL AHMED.
Basic Queries Specifying Columns
Creating Macro Variables in SQL (Review)
3 Macro Storage.
Conditional Processing
SAS in Data Cleaning.
The relational operators
Correlated Subqueries
Chapter 7: Macros in SAS Macros provide for more flexible programming in SAS Macros make SAS more “object-oriented”, like R Not a strong suit of text ©
3 Macro Parameters.
© Akhilesh Bajaj, All rights reserved.
A more complex example.
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Indirect References to Macro Variables
Creating Macro Variables in the DATA Step
Defining and Calling a Macro
Introduction to DATA Step Programming SAS Basics II
SESUG Web Scraping in SAS: A Macro-Based Approach
Global and Local Symbol Tables
How to Create Data Driven Lists
Retrieving Macro Variables in the DATA Step
3 Iterative Processing.
Hunter Glanz & Josh Horstman
Using Macros to Solve the Collation Problem
Dictionary Tables and Views, obtain information about SAS files
Meta-Analysis Glass (Education Researcher, 5:3-8; 1976) suggested that there were three types of analyses: Primary analysis tests the hypothesis for.
Examining model stability, an example
Combining Data Sets in the DATA step.
Let’s Talk About Variable Attributes
Detecting Runtime Errors and Exiting from Nested Macros Gracefully
Trigger %macro check_trigger_run;
Passing Simple and Complex Parameters In and Out of Macros
Python Basics with Jupyter Notebook
CGHS HERITAGE QUEST PRESENTATION
Tips and Tricks for Using Macros to Automate SAS Reporting.
Methods/Functions.
Hans Baumgartner Penn State University
Writing Robust SAS Macros
Presentation transcript:

3 Parameter Validation

Perform parameter validation with the OR operator Perform parameter validation with the OR operator. Perform parameter validation with the IN operator. Perform data-driven parameter validation. Perform parameter validation with the %INDEX function.

Example: Validate a parameter value before generating SAS code that is based on that value. %macro customers(place); %let place=%upcase(&place); %if &place=AU or &place=CA or &place=DE or &place=IL or &place=TR or &place=US or &place=ZA %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %put Sorry, no customers from &place..; %mend customers; %customers(de) %customers(aa)

Example: Use the IN operator for parameter validation. %macro customers(place) / minoperator; %let place=%upcase(&place); %if &place in AU CA DE IL TR US ZA %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %put Sorry, no customers from &place..; %mend customers; %customers(de) %customers(aa) The MINOPERATOR option is required.

%macro customers(place) / minoperator; %let place=%upcase(&place); proc sql noprint; select distinct country into :list separated by ' ' from orion.customer; quit; %if &place in &list %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %do; %put Sorry, no customers from &place..; %put Valid countries are: &list..; %mend customers; %customers(de) %customers(aa) proc sql noprint; select distinct country into :list separated by ' ' from orion.customer; quit;

The %INDEX Function Use the %INDEX function to check the value of a macro variable against a list of valid values. General form of the %INDEX function: The %INDEX function does the following: searches argument1 for the first occurrence of argument2 returns an integer representing the position in argument1 of the first character of argument2 if there is an exact match returns 0 if there is no match %INDEX(argument1, argument2) The example which follows parallels the previous example, but uses %INDEX to mimic the macro IN operator. This would be of interest to folks who have not upgraded to SAS 9.2, the release in which the macro IN operator became permanently available.

The %INDEX Function %INDEX(argument1, argument2) argument1 and argument2 can be the following: constant text macro variable references macro functions macro calls

Example: Use the %INDEX function for parameter validation. %macro customers(place); %let place=%upcase(&place); proc sql noprint; select distinct country into :list separated by '*' from orion.customer; quit; %if %index(*&list*,*&place*) > 0 %then %do; proc print data=orion.customer; var customer_name customer_address country; where upcase(country)="&place"; title "Customers from &place"; run; %end; %else %do; %put Sorry, no customers from &place..; %put Valid countries are: &list..; %mend customers; Note the use of asterisks.