How to Create Data Driven Lists

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

1 Jerry Tsai This presentation and code available at: clintuition.com/pubs/
Axio Research E-Compare A Tool for Data Review Bill Coar.
SAS Programming Techniques for Decoding Variables on the Database Level By Chris Speck PAREXEL International RTSUG – Wednesday, March 23, 2011.
By Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson, Linda Lau, Jerri Williams Chapter 10 Using Macros and SQL in Access 1.
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
The New SAS Engine For CRSP   Benefits of using SAS engine for CRSP   Setting up the interface between SAS and CRSP   Examples of use   Performance.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
SAS SQL SAS Seminar Series
SAS Macros ® 101 How I learned to stop worrying and love macros Alex Chaplin BCS USA Section.
Managing Passwords in the SAS System Allen Malone Senior Analyst/Programmer Kaiser Permanente.
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.
PROC SQL: Tips and Translations for Data Step Users By: Gail Jorgensen Susan Marcella.
1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work.
Copyright © 2006, SAS Institute Inc. All rights reserved. SAS Enterprise Guide Old Proc – New Tricks? Tim Trussell Academic Program, SAS Canada world diabetes.
Macro Overview Mihaela Simion. Macro Facility Overview Definition : The SAS Macro Facility is a tool within base SAS software that contains the essential.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
Tips & Tricks From your fellow SAS users 9/30/2004.
Doug Haigh, SAS Institute Inc.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
SAS/AF ® Application Development New Hampshire / Vermont SAS ® Users Group 18 June, 2004 Stephen Kearing, MS.
Copyright © 2004, SAS Institute Inc. All rights reserved. SASHELP Datasets A real life example Barb Crowther SAS Consultant October 22, 2004.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
CSD 340 (Blum)1 For Loops See Beginning JavaScript (Paul Wilton) p. 87.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
Hints and Tips SAUSAG Q SORTING – NOUNIQUEKEY The NOUNIQUEKEY option on PROC SORT is a useful way in 9.3 to easily retain only those records with.
SAUSAG 71 – 21 Aug 2014 Tech Tips Jerry Le Breton On behalf of the SAUSAG Committee.
SAS and Other Packages SAS can interact with other packages in a variety of different ways. We will briefly discuss SPSSX (PASW) SUDAAN IML SQL will be.
Tips for Mastering Relational Databases Using SAS/ACCESS®
Introduction to Database Systems, CS420
Advantages of sas for reporting
(or SASopardy, if you will)
SAS Macro Language.
Python Lesson 12 Mr. Kalmes.
Creating Macro Variables in SQL (Review)
Chapter 18: Modifying SAS Data Sets and Tracking Changes
Conditional Processing
GENERICITY New Metadata Concepts Applied to SAS Macro Programming
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 ©
SAS Essentials How SAS Thinks
A Better Way to Flip (Transpose) a SAS® Dataset
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
Chapter 6 Variable Screening Methods.
Macro Variable’s scope
Defining and Calling a Macro
3 Iterative Processing.
Increase Your Productivity by Doing Less
Hunter Glanz & Josh Horstman
3.5- The while Statement The while statement has the following syntax:
Lisa Mendez, PhD & Andrew Kuligowski
Dictionary Tables and Views, obtain information about SAS files
Examining model stability, an example
3 Parameter Validation.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Never Cut and Paste Again
Let’s Talk About Variable Attributes
Data Management Module: Creating, Adding and Dropping Variables
Automate Repetitive Programming Tasks: Effective SAS® Code Generators
Detecting Runtime Errors and Exiting from Nested Macros Gracefully
You deserve ARRAYs! How to be more efficient using SAS®
Trigger %macro check_trigger_run;
Passing Simple and Complex Parameters In and Out of Macros
FLUENCY WITH INFORMATION TECNOLOGY
Topics Introduction to Repetition Structures
Data tmp; do i=1 to 10; output; end; run; proc print data=tmp;
Frank DiIorio CodeCrafters, Inc. Philadelphia PA
Writing Robust SAS Macros
Presentation transcript:

How to Create Data Driven Lists By Kate Burnett-Isaacs Copyright © 2010, SAS Institute Inc. All rights reserved.

Introduction We often want our code or program logic to be driven by the data at hand, rather than be directed by us Lists can be used to verify the data at hand or can be used in later steps of the program Dynamic code can write our lists once and ensure that the values change in tandem with our data This presentation will present the concepts of creating data-driven lists for observations, variables, and data sets

Macro Programming Macro programming is critical to creating data-driven processes Macros allow for code to be generalized and execution logic to vary with the data provided The macro concepts presented include: the timing of macro references and execution in relation to DATA steps or procedures; defining macros and macro variables; calling and executing macro code; and some basic conditional macro programming. A useful resource for more information on macro programming is Carpenter’s Complete Guide to the SAS Macro Language (2004). #SASGF Copyright © 2016, SAS Institute Inc. All rights reserved.

Data: Toy Sales for Quarter 4, 2015 #SASGF Copyright © 2016, SAS Institute Inc. All rights reserved.

Data-driven List of Observations %macrolistobs; proc sql noprint; select distinct ToyCategory into :listofcategories separated by ', ' from ToySales; quit; %mend; %listobs; Books, Costumes, Dolls, Games, Holiday, Misc

Data-driven List of Variables %macro listvar; proc sql noprint; select Name into :listvars separated by ' ' from dictionary.Columns where (libname = 'WORK') AND (memname = 'TOYSALES'); quit; %mend; %listvar; Year Month ToyCategory Sales

Data-driven List of Datasets %macro tablenames; proc sql noprint; select memname into :listtable separated by ' ' from dictionary.members WHERE (libname = 'WORK'); quit; %mend; %tablenames; SASMACR TOYSALES

Data-driven List of Datasets Option 2 What if we want only certain datasets in our list? We need a data-driven list of datasets then we need to create datasets dynamically Use macro %DO loops where a new dataset is created in each iteration of the loop. We cannot just set a macro variable to be the dataset created in each iteration, because it will get overwritten with each pass.

Data-driven List of Datasets Option 2: Code %macro datasetlist; %let datasetlist= ; %do i=10 %to 12; data Sales_month&i.; set ToySales; where month=&i.; drop month; rename Sales=Sales_&i.; run; %let datasetlist= &datasetlist. Sales_month&i.; %end; %mend; %datasetlist;

First Iteration: i=10 Prior to DATA step: datasetlist= ; data Sales_month10; set ToySales; where month=10; drop month; rename Sales=Sales_10; run; After DATA step: %let datasetlist= Sales_month10;

Second Iteration: i=11 Prior to DATA step: datasetlist = Sales_month10; data Sales_month11; Set ToySales; where month=11; drop month; rename Sales=Sales_11; run; After DATA step: %let datasetlist= Sales_month10 Sales_month11;

Third Iteration: i=12 Prior to DATA step: datasetlist=Sales_month10 Sales_month11; data Sales_month12; Set ToySales; where month=12; drop month; rename Sales=Sales_12; run; After DATA step: %let datasetlist= Sales_month10 Sales_month11 Sales_month12;

Conclusion By using key concepts of macro programming, such as defining, calling and executing macros and macro variables, we can dynamically program and then use our lists. Using procedures and the SELECT statement, we can create lists of observations and variables. Creating a list of datasets requires a little out of the box thinking

#SASGF Copyright © 2016, SAS Institute Inc. All rights reserved.