Dynamic Generation of Data Steps on basis of Unique By-Group Permutations David Rosenfeld City of Toronto.

Slides:



Advertisements
Similar presentations
DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.
Advertisements

Axio Research E-Compare A Tool for Data Review Bill Coar.
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Introduction to Assembly language
Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
1 Eliminate Cookie-Cutter Code with %wordLoop 1
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
CS 280 Data Structures Professor John Peterson. Next Project YET ANOTHER SORT! We’ll do Quicksort using links instead of arrays. Wiki time.
Thinking inside the box 26 June 2003 Soar Workshop - Slide 1 © 2003 Soar Technology, Inc. Thinking… …inside the box SoarDoc Presented on Thursday, 26 June.
Progress Presentation. Tasks Completed I have resolved most of the bugs in the previous graphs of stanford to the world monitoring data. Completed work.
Basic And Advanced SAS Programming
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
1 General Reporting HRMS Reports There are two types of HRMS reports: Standard and Customized. Standard reports came with the SAP Software and relate to.
Generating Random Samples SAS, EXCEL, JMP, SPSS. Population of Data  Sample Data should be in a dataset where each row represents an individual unit,
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks.
Writing Maintainable Code with ‘Style’ Allan Page Senior Marketing Analyst Canadian Tire Bank.
Stacking Rich Text Format (RTF) - %SRiT Duong Tran – Independent Contractor, London, UK Stacking Rich Text Format (RTF) - %SRiT Duong Tran – Independent.
1 Data List Spreadsheets or simple databases - a different use of Spreadsheets Bent Thomsen.
Key Data Management Tasks in Stata
1 Performing Spreadsheet What-If Analysis Applications of Spreadsheets.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Launch SpecE8 and React from GSS. You can use the chemical analyses in a GSS data sheet to set up and run SpecE8 and React calculations. Analysis → Launch…
VUID Tools: Designing Ease of Mind Matt Shomphe Phil Shinn.
A dynamic reporting system Catering to the needs of many Pascal Hanssens Senior Statistical Programmer Statistical Programming Business & Decision Life.
Macro Overview Mihaela Simion. Macro Facility Overview Definition : The SAS Macro Facility is a tool within base SAS software that contains the essential.
Introduction to Using the Data Step Hash Object with Large Data Sets Richard Allen Peak Stat.
1 SAS 1-liners SAS Coding Efficiencies. 2 Overview Less is more Always aim for robust, reusable and efficient code Coding efficiency versus processing.
TASS Meeting Copy and Paste from Excel to SAS September 19th, 2008 Copy and Paste from Excel to SAS Dr. Arthur Tabachneck, Director Data Management with.
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
Macro Variable Resolution Enio Presutto York University, Toronto, Canada.
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.
Code Generation. 2 Overview of presentation Goal Background Dynamic SQL Method Examples.
ME 142 Engineering Computation I Exam 2 Review VBA.
Creating and Using Custom Formats for Data Manipulation and Summarization Presented by John Schmitz, Ph.D. Schmitz Analytic Solutions, LLC Certified Advanced.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
Nick Kwolek David Duemeler Martin PendergastStephen Edwards.
For Code Next For Code Next A loop is a segment of a code that repeats (changing slightly each time)
Excel Wrap-Up. What tab is used to access macro functionality in Excel? The Developer tab Know what a recorded macro is as well as its advantages and.
Common Sense Validation Using SAS Lisa Eckler Lisa Eckler Consulting Inc. TASS Interfaces, December 2015.
TASS Meeting Setting GuessingRows when Importing Excel Files September 19th, 2008 Setting GuessingRows when importing Excel Files Dr. Arthur Tabachneck,
Practical Uses of the DOW Loop Richard Allen Peak Stat April 8, 2009.
Copyright © 2004, SAS Institute Inc. All rights reserved. SASHELP Datasets A real life example Barb Crowther SAS Consultant October 22, 2004.
An Introduction to Proc Transpose David P. Rosenfeld HR Consultant, Workforce Planning & Data Management City of Toronto.
1 GLOBAL BIOMETRICS Biostatistics Clinical Data Management Epidemiology & Patient Reported Outcomes Statistical Programming and Analysis Strategic Planning,
Efficiently Solving Computer Programming Problems Doncho Minkov Telerik Corporation Technical Trainer.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Use SAS to Automate Hospital Reports generation Cardiac Service BC Stats Team, PHSA Tina Yang.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
TASS Meeting Quickly Finding Project Code March 13th, 2009 A way to quickly find all of your project code Dr. Arthur Tabachneck Director, Data Management.
Beautiful PROC CONTENTS Output Using the ODS Excel Destination Suzanne Dorinski SESUG 2015 Disclaimer: Any views expressed are those of the author and.
Greg Steffens Noumena Solutions
SAS Macro Language.
Changing WRF input files (met_em…) with MATLAB
Lecture 4B More Repetition Richard Gesick
PROC DOC III: Self-generating Codebooks Using SAS®
Creating the Example Data
Beautiful PROC CONTENTS Output Using the ODS Excel Destination
C Graphing Functions.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
3 Iterative Processing.
Hunter Glanz & Josh Horstman
Lisa Mendez, PhD & Andrew Kuligowski
Automating SAS through the Power of VB Script
Trigger %macro check_trigger_run;
Tips and Tricks for Using Macros to Automate SAS Reporting.
C. M. Overstreet Old Dominion University Fall 2005
Writing Robust SAS Macros
Presentation transcript:

Dynamic Generation of Data Steps on basis of Unique By-Group Permutations David Rosenfeld City of Toronto

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations the data the problem a solution the macro the output the conclusion Overview

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations data tass_sample; input division $10. score; label score='Test Score'; cards; Division_A 1 Division_B 2 Division_B 8 Division_B 7 Division_B 6 Division_A 5 ; The Data

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations need to export separate worksheets for each division the task has to be repeated every week don’t know which divisions will be in the data file don’t want to hardcode (and have to change) the program every week The Problem

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations dynamically produce the desired datasets use subsetting criteria based on the values of a ‘by’ variable A Solution * Create a Macro to: derived from sample

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations %macro groups(dsn,byvar,export_to); /* First sort the data in order of the */ /* by variable */ proc sort data=&dsn.; by &byvar.; run; The Macro

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations %macro groups(dsn,byvar,export_to); /* First sort the data in order of the */ /* by variable */ proc sort data=&dsn.; by &byvar.; run; The Macro /* Then, create a macro variable, VARn, for */ /* each BY-Group and a counter of the number */ /* of new macro variables created. */ data _null_; set &dsn. end=eof; by &byvar.; if first.&byvar. then do; flag+1; call symput('var'||put(flag,8. -L),&byvar.); end; if eof then call symput('tot',put(flag,8. -L)); run;

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations %macro groups(dsn,byvar,export_to); /* First sort the data in order of the */ /* by variable */ proc sort data=&dsn.; by &byvar.; run; The Macro /* Then, create a macro variable, VARn, for */ /* each BY-Group and a counter of the number */ /* of new macro variables created. */ data _null_; set &dsn. end=eof; by division; if first.division then do; flag+1; call symput('var'||put(flag,8. -L),division); end; if eof then call symput('tot',put(flag,8. -L)); run; /* Loop through all the macro variables and */ /* create a separate file for each by variable */ data %do i=1 %to &tot; &&var&i %end;; set &dsn; %do i=1 %to &tot; if &byvar="&&var&i" then output &&var&i; %end; run;

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations %macro groups(dsn,byvar,export_to); /* First sort the data in order of the */ /* by variable */ proc sort data=&dsn.; by &byvar.; run; The Macro /* Then, create a macro variable, VARn, for */ /* each BY-Group and a counter of the number */ /* of new macro variables created. */ data _null_; set &dsn. end=eof; by division; if first.division then do; flag+1; call symput('var'||put(flag,8. -L),division); end; if eof then call symput('tot',put(flag,8. -L)); run; /* Loop through all the macro variables and */ /* create a separate file for each by variable */ data %do i=1 %to &tot; &&var&i %end;; set &dsn; %do i=1 %to &tot; if &byvar="&&var&i" then output &&var&i; %end; run; /* Loop through all the macro variables and */ /* export a sheet for each by variable */ %do j=1 %to &tot; PROC EXPORT DATA= WORK.&&var&j OUTFILE= "&export_to." DBMS=EXCEL REPLACE; /* dbdsopts='dblabel=yes'; */ SHEET="&&var&j"; RUN; %end; %mend groups;

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations %macro groups(dsn,byvar,export_to); /* First sort the data in order of the */ /* by variable */ proc sort data=&dsn.; by &byvar.; run; The Macro /* Then, create a macro variable, VARn, for */ /* each BY-Group and a counter of the number */ /* of new macro variables created. */ data _null_; set &dsn. end=eof; by division; if first.division then do; flag+1; call symput('var'||put(flag,8. -L),division); end; if eof then call symput('tot',put(flag,8. -L)); run; /* Loop through all the macro variables and */ /* create a separate file for each by variable */ data %do i=1 %to &tot; &&var&i %end;; set &dsn; %do i=1 %to &tot; if &byvar="&&var&i" then output &&var&i; %end; run; /* Loop through all the macro variables and */ /* export a sheet for each by variable */ %do j=1 %to &tot; PROC EXPORT DATA= WORK.&&var&j OUTFILE= "&export_to." DBMS=EXCEL REPLACE; /* dbdsopts='dblabel=yes'; */ SHEET="&&var&j"; RUN; %end; %mend groups; /* Run the macro */ %groups(work.tass_sample, division, c:\data_driven_demo.xls)

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations The Output

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations remove annoying drudgery avoid having to continually check data eliminate tedious and inefficient hard coding promote automated and easily maintained sparse code have code that is flexible and reacts to data transparently Conclusion a useful method to:

June 11, 2010 TASS Dynamic Generation of Data Steps on basis of Unique By-Group Permutations Questions?