SAS Macro Language.

Slides:



Advertisements
Similar presentations
Council of Public Relations Firms 2012 Domestic Compensation and Benefits Survey Survey Overview and Proposed Changes COUNCIL of PUBLIC RELATIONS FIRMS.
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.
Appraisal Institute State of Atlanta Housing Market.
MediaLoft Eastern Division 2003 Fiscal Year. Eastern Division Stores MediaLoft Boston MediaLoft New York MediaLoft Chicago MediaLoft Kansas City.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
“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 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.
Lecture 5 Sorting, Printing, and Summarizing Your Data.
SAS SQL Part 2 Alan Elliott. Dealing with Missing Values Title "Dealing with Missing Values in SQL"; PROC SQL; select INC_KEY,GENDER, RACE, INJTYPE, case.
COMPANY NEWS UPDATE Doug Olzenak - President. VISION With a progressive and proactive culture, Allied Vaughn will be an organization that provides industry-leading.
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
Review Questions Part Identify major fashion centers, types of designers, and price market categories.
1 SAS 1-liners SAS Coding Efficiencies. 2 Overview Less is more Always aim for robust, reusable and efficient code Coding efficiency versus processing.
2012 House Results Map Updated November 12, 2012 Producer: Jenna Fugate Director: Jessica Guzik.
1 Efficient SAS Coding with Proc SQL When Proc SQL is Easier than Traditional SAS Approaches Mike Atkinson, May 4, 2005.
1 Filling in the blanks with PROC FREQ Bill Klein Ryerson University.
Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.
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.
Tips & Tricks From your fellow SAS users 9/30/2004.
State SOL History Review USII.4e-USII.6d What are the negative effects of industrialization? Child labor Low wages, long hours Unsafe working conditions.
YET ANOTHER TIPS, TRICKS, TRAPS, TECHNIQUES PRESENTATION: A Random Selection of What I Learned From 15+ Years of SAS Programming John Pirnat Kaiser Permanente.
What city is this? San Francisco Name the state with the star.
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.
Annual Water Year Budgets (01 Oct – 30 Sep) Water year 1980 = 01 Oct 1979 – 30 Sep 1980 Showing 6 NCA regions and 2 river basins Showing 5 NCA-LDAS simulations.
Patrick Thornton SRI International.  Example of a Multiple Response Item ◦ Variable coding and example data  A Cross Tabulation using Proc REPORT 
22 Copyright © 2009, Oracle. All rights reserved. Filtering Requests in Oracle Business Intelligence Answers.
Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.
Convention Centres of Canada July 15-18th, Calgary, AB
Session 1 Retrieving Data From a Single Table
2c: States grouped by region
Chapter 5: Passing and Processing Macro Parameters
September 11, 2017 U.S. History Agenda: DO NOW: City Matching
An Example of Analyses of a Distance Matrix
Greg Steffens Noumena Solutions
Exploration and Settlement until 1675
A region is a large area that has common
US Physical Characteristics
Creating Macro Variables in SQL (Review)
Conditional Processing
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.
Regions of the United States
US Physical Characteristics
Unit 3 Lesson 5: Regional Cities
September 10, 2018 U.S. History Agenda: DO NOW: City Matching
What major features make up the U. S. ’s Northeast and South Regions
Defining and Calling a Macro
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
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.
3 Parameter Validation.
Detecting Runtime Errors and Exiting from Nested Macros Gracefully
Trigger %macro check_trigger_run;
Passing Simple and Complex Parameters In and Out of Macros
or, “Check Your Balls with SAS Arrays”
Country “Quilt” Project: una introducciÓn
Tips and Tricks for Using Macros to Automate SAS Reporting.
Hans Baumgartner Penn State University
Why We Need Car Parking Systems - Wohr Parking Systems
Types of Stack Parking Systems Offered by Wohr Parking Systems
Add Title.
Presentation transcript:

SAS Macro Language

Write and debug SAS program without macro coding Generalize by replacing hard coded values with macro variable references Create a macro definition with macro parameters Add macro level programming for conditional and iterative processing Add data driven customization

Marketing Data region city product sales revenue Northeast New York sedan 400 100 Northeast Boston coupe 800 200 Midwest Chicago minivan 200 50 Midwest Detroit suv 100 25 Northwest Seattle sedan 600 150 Northwest Boise coupe 20 5 Southeast Raleigh minivan 200 50 Southeast Atlanta suv 400 100 Southwest Dallas sedan 1000 250 Southwest Houston coupe 2000 500

Write and debug SAS program without macro coding proc sort data=lib1.marketing (where=(region="Northeast")) out=sales; by city product; run; title1 "Sales Report for Northeast Region"; proc print data=sales noobs; var city product sales revenue;

Write and debug SAS program without macro coding Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

Generalize by replacing hard coded values with macro variable references %let region = Northeast; %let sortvar = city product; proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; run; title1 "Sales Report for &region Region"; proc print data=sales noobs; var &sortvar sales revenue; %put region=&region sortvar=&sortvar;

Generalize by replacing hard coded values with macro variable references Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

Create a macro definition with macro parameters %macro sales (region=, sortvar=city product); proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; run; title1 "Sales Report for &region Region"; proc print data=sales noobs; var &sortvar sales revenue; %put region=&region sortvar=&sortvar; %mend sales; %sales (region=Northeast);

Create a macro definition with macro parameters Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

Add macro level programming for conditional and iterative processing %macro sales (region=, sortvar=city product) / minoperator; %let reglist = Northeast Midwest Northwest Southeast Southwest; %if &region in &reglist %then %do; proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; run; title1 "Sales Report for &region Region"; proc print data = sales noobs; var &sortvar sales revenue; %end; %else %put Invalid value for region=&region; %mend sales; %sales (region=Northeast);

Add macro level programming for conditional and iterative processing Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

Add data driven customization %macro sales (region=,sortvar=city product) / minoperator; proc sql noprint; select distinct region into :reglist separated by " " from lib1.marketing; quit; %put reglist=&reglist; %if &region in &reglist %then %do; proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; title1 "Sales Report for &region Region"; proc print data = sales noobs; var &sortvar sales revenue; run; %end; %else %put No customers on file from region=&region; %mend sales; %sales (region=Northeast);

Add data driven customization Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

Questions?