Using Macros to Solve the Collation Problem

Slides:



Advertisements
Similar presentations
Chapter 5: Creating and Managing Tables using PROC SQL 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Advertisements

SALES INTRODUCTION.  Overview  Scenario  How do we do it now?  The Solution  How it Works  Benefits  Target Markets  Supported MFD’s Content.
Chapter 9: Introducing Macro Variables 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Managing Processing Using PROC SQL Chapter 8 1 Imelda Go, John Grego, Jennifer Lasecki, 2011.
Performing Queries Using PROC SQL Chapter 1 1 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 13: Creating Samples and Indexes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Assignmnet: Simple Random Sampling With Replacement Some Solutions.
Assignmnet: Simple Random Sampling With Replacement Some Solutions.
PROC SQL – Select Codes To Master For Power Programming Codes and Examples from SAS.com Nethra Sambamoorthi, PhD Northwestern University Master of Science.
Chapter 18: Modifying SAS Data Sets and Tracking Changes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 3: Combining Tables Horizontally using PROC SQL 1 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
CHAPTER 7-1 SOLVING SYSTEM OF EQUATIONS. WARM UP  Graph the following linear functions:  Y = 2x + 2  Y = 1/2x – 3  Y = -x - 1.
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.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Develop Effective Products and Services
©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina Chapter 17 supplement: Review of Formatting Data STAT 541.
Chapter 15: Combining Data Horizontally 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
Chapter 16: Using Lookup Tables to Match Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 19: Introduction to Efficient SAS Programming 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
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.
Chapter 4: Combining Tables Vertically using PROC SQL 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
Chapter 23: Selecting Efficient Sorting Strategies 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 8: Using Basic Statistical Procedures “33⅓% of the mice used in the experiment were cured by the test drug; 33⅓% of the test population were unaffected.
Chapter 21: Controlling Data Storage Space 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
Chapter 14: Combining Data Vertically 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
Session 1 Retrieving Data From a Single Table
Chapter 5: Enhancing Your Output with ODS
Applied Business Forecasting and Regression Analysis
Chapter 6: Set Operators
Chapter 6: Modifying and Combining Data Sets
Chapter 19: Introduction to Efficient SAS Programming
Chapter 8: ODS Graphics ODS graphics were not available prior to SAS 9.2 They have been implemented across a wide range of procedures Functionality isn’t.
Chapter 3: Working With Your Data
PROC SQL, Overview.
Chapter 13: Creating Samples and Indexes
SAS Output Delivery System
Chapter 18: Modifying SAS Data Sets and Tracking Changes
3 Macro Storage.
Former Chapter 23: Selecting Efficient Sorting Strategies
Conditional Processing
Chapter 4: Sorting, Printing, Summarizing
Assume as previously that we have k samples on as many treatments
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.
Chapters 5 and 7 supplement
Data Analysis and Statistical Software I ( ) Quarter: Autumn 02/03
Chapter 24 (4th ed.): Creating Functions
Quick Data Summaries in SAS
Beautiful PROC CONTENTS Output Using the ODS Excel Destination
Defining and Calling a Macro
How are your SAS Skills? Chapter 1: Accessing Data (Question # 1)
3 Iterative Processing.
3 Parameter Validation.
Producing Descriptive Statistics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Chapter 24: Querying Data Efficiently
Daniela Stan Raicu School of CTI, DePaul University
Agenda Helper Demonstrator File
Heart Rate Lab.
Wilcoxon Rank-Sum Test
Writing Robust SAS Macros
Changing a file from being long to being wide*
Presentation transcript:

Using Macros to Solve the Collation Problem STAT 541 Using Macros to Solve the Collation Problem ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina

The term collate refers to collecting or arranging (pages) in proper order. SAS provides the convenience of BY-group processing in many of its procedures. BY-group processing produces output for the different groups of interest, but the default output may not be in the desired order.

Example PROC SORT DATA=MASTER; BY SCHOOL; PROC PRINT DATA=MASTER; BY SCHOOL; PAGEBY SCHOOL; VAR SSN LAST FIRST MI EXEMPT; TITLE ’Student Names and Exemption Status’; PROC MEANS DATA=MASTER; BY SCHOOL; VAR GPA; TITLE ’Average GPA’; PROC FREQ DATA=MASTER; BY SCHOOL; TABLES STANINE; TITLE ’Distribution of Reading Test Stanines’; PAGEBY prints a new page. A stanine is a standardized 9-point scale with mean=5 and sd=2.

The preceding example will produce output by school per procedure. What if the desired output is to have all the output from each school together across procedures? This can be easily solved using a number of different strategies.

A Solution %MACRO REPORTS (BEGIN, END); %DO INDEX=&BEGIN %TO &END; OPTIONS PAGENO=1; DATA SCHOOL&INDEX; SET MASTER; IF SCHOOL=&INDEX; PROC PRINT DATA=SCHOOL&INDEX; BY SCHOOL; VAR SSN LAST FIRST MI EXEMPT; TITLE ’Student Names and Exemption Status’; PROC MEANS DATA=SCHOOL&INDEX; VAR GPA; TITLE ’Average GPA’; PROC FREQ DATA=SCHOOL&INDEX; TABLES STANINE; TITLE ’Distribution of Reading Test Stanines’; %END; %MEND REPORTS; **THE FOLLOWING STATEMENT GENERATES REPORTS FOR 50 SCHOOLS; %REPORTS(1,50) For the purpose of providing an example, the schools are numbered or indexed conveniently from 1 to 50. A data set created for each school is used one at a time with the procedures. The macro parameters BEGIN and END are useful in case there is a need to generate reports for just a number of schools. %REPORTS(3,3) will generate the reports for just the 3rd school. %REPORTS(14,25) will generate reports for the 14th through 25th schools. In the example, %INCLUDE is a chapter 12 feature. We should probably have a more sophisticated method to handle indexing of schools.

Another Solution %MACRO REPORTS (BEGIN, END); %DO INDEX=&BEGIN %TO &END; OPTIONS PAGENO=1; PROC PRINT DATA=MASTER; BY SCHOOL; VAR SSN LAST FIRST MI EXEMPT; WHERE SCHOOL=&INDEX; TITLE ’Student Names and Exemption Status’; PROC MEANS DATA=MASTER; VAR GPA; TITLE ’Average GPA’; PROC FREQ DATA=MASTER; TABLES STANINE; TITLE ’Distribution of Reading Test Stanines’; %END; %MEND REPORTS; %REPORTS (1,50) The WHERE statement was used so that the only data set needed for the procedures is MASTER. In this example, we avoid creating WORK.SCHOOL1, WORK.SCHOOL2, etc.