Christopher Louden University of Texas Health Science Center at San Antonio

Similar documents
SD10 A SAS MACRO FOR PERFORMING BACKWARD SELECTION IN PROC SURVEYREG

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

Base and Advance SAS

SAS Online Training: Course contents: Agenda:

Going Under the Hood: How Does the Macro Processor Really Work?

Getting it Done with PROC TABULATE

An Easy Route to a Missing Data Report with ODS+PROC FREQ+A Data Step Mike Zdeb, FSL, University at Albany School of Public Health, Rensselaer, NY

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp.

Arthur L. Carpenter California Occidental Consultants, Oceanside, California

Want to Do a Better Job? - Select Appropriate Statistical Analysis in Healthcare Research

Contents of SAS Programming Techniques

Generating Customized Analytical Reports from SAS Procedure Output Brinda Bhaskar and Kennan Murray, RTI International

3. Almost always use system options options compress =yes nocenter; /* mostly use */ options ps=9999 ls=200;

SAS CURRICULUM. BASE SAS Introduction

AURA ACADEMY SAS TRAINING. Opposite Hanuman Temple, Srinivasa Nagar East, Ameerpet,Hyderabad Page 1

Short Notes of CS201

SAS Macro Dynamics - From Simple Basics to Powerful Invocations Rick Andrews, Office of the Actuary, CMS, Baltimore, MD

GET A GRIP ON MACROS IN JUST 50 MINUTES! Arthur Li, City of Hope Comprehensive Cancer Center, Duarte, CA

CS201 - Introduction to Programming Glossary By

Introduction. Getting Started with the Macro Facility CHAPTER 1

Lecture 1 Getting Started with SAS

Template Versatility Using SAS Macro Language to Generate Dynamic RTF Reports Patrick Leon, MPH

USING DATA TO SET MACRO PARAMETERS

A Cross-national Comparison Using Stacked Data

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools

Quick Results with the Output Delivery System

SAS Macro Dynamics: from Simple Basics to Powerful Invocations Rick Andrews, Office of Research, Development, and Information, Baltimore, MD

Using SAS to Analyze CYP-C Data: Introduction to Procedures. Overview

Unlock SAS Code Automation with the Power of Macros

Essential ODS Techniques for Creating Reports in PDF Patrick Thornton, SRI International, Menlo Park, CA

BASICS BEFORE STARTING SAS DATAWAREHOSING Concepts What is ETL ETL Concepts What is OLAP SAS. What is SAS History of SAS Modules available SAS

Building Sequential Programs for a Routine Task with Five SAS Techniques

Using SAS Macro to Include Statistics Output in Clinical Trial Summary Table

ABSTRACT MORE THAN SYNTAX ORGANIZE YOUR WORK THE SAS ENTERPRISE GUIDE PROJECT. Paper 50-30

DSCI 325: Handout 15 Introduction to SAS Macro Programming Spring 2017

SAS Macro Language: Reference

ABSTRACT INTRODUCTION MACRO. Paper RF

Statistics and Data Analysis. Common Pitfalls in SAS Statistical Analysis Macros in a Mass Production Environment

An Introduction to SAS Macros

Combining the Results from Multiple SAS PROCS into a Publication Quality Table

From An Introduction to SAS University Edition. Full book available for purchase here.

Functions vs. Macros: A Comparison and Summary

Square Peg, Square Hole Getting Tables to Fit on Slides in the ODS Destination for PowerPoint

A Lazy Programmer s Macro for Descriptive Statistics Tables

Manipulating Statistical and Other Procedure Output to Get the Results That You Need

THE IMPACT OF DATA VISUALIZATION IN A STUDY OF CHRONIC DISEASE

Correcting for natural time lag bias in non-participants in pre-post intervention evaluation studies

Posters. Paper

Summary Table for Displaying Results of a Logistic Regression Analysis

2. Don t forget semicolons and RUN statements The two most common programming errors.

Customized Flowcharts Using SAS Annotation Abhinav Srivastva, PaxVax Inc., Redwood City, CA

Workbooks (File) and Worksheet Handling

SAS Training BASE SAS CONCEPTS BASE SAS:

A Quick and Gentle Introduction to PROC SQL

CHAPTER 7 Using Other SAS Software Products

22S:166. Checking Values of Numeric Variables

Summarizing Impossibly Large SAS Data Sets For the Data Warehouse Server Using Horizontal Summarization

SAS 9 Programming Enhancements Marje Fecht, Prowerk Consulting Ltd Mississauga, Ontario, Canada

Paper CC06. a seed number for the random number generator, a prime number is recommended

STAT 3304/5304 Introduction to Statistical Computing. Introduction to SAS

SAS Example A10. Output Delivery System (ODS) Sample Data Set sales.txt. Examples of currently available ODS destinations: Mervyn Marasinghe

A Macro to Manage Table Templates Mark Mihalyo, Community Care Behavioral Health Organization, Pittsburgh, PA

Data Quality Review for Missing Values and Outliers

/ * %STR(argument) %NRSTR(argument)

Efficiency Programming with Macro Variable Arrays

A Way to Work with Invoice Files in SAS

Please login. Take a seat Login with your HawkID Locate SAS 9.3. Raise your hand if you need assistance. Start / All Programs / SAS / SAS 9.

BUSINESS ANALYTICS. 96 HOURS Practical Learning. DexLab Certified. Training Module. Gurgaon (Head Office)

SESUG Paper AD A SAS macro replacement for Dynamic Data Exchange (DDE) for use with SAS grid

An Introduction to Macros Deb Cassidy

Using Templates Created by the SAS/STAT Procedures


Cover the Basics, Tool for structuring data checking with SAS Ole Zester, Novo Nordisk, Denmark

Cleaning Duplicate Observations on a Chessboard of Missing Values Mayrita Vitvitska, ClinOps, LLC, San Francisco, CA

Using Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse

Submitting SAS Code On The Side

RWI not REI a Robust report writing tool for your toughest mountaineering challenges.

Paper CC-016. METHODOLOGY Suppose the data structure with m missing values for the row indices i=n-m+1,,n can be re-expressed by

ODS DOCUMENT, a practical example. Ruurd Bennink, OCS Consulting B.V., s-hertogenbosch, the Netherlands

Introduction to SAS Procedures SAS Basics III. Susan J. Slaughter, Avocet Solutions

RUN_MACRO Run! With PROC FCMP and the RUN_MACRO Function from SAS 9.2, Your SAS Programs Are All Grown Up

Sandra Hendren Health Data Institute

Using PROC SQL to Calculate FIRSTOBS David C. Tabano, Kaiser Permanente, Denver, CO

186 Statistics, Data Analysis and Modeling. Proceedings of MWSUG '95

%MISSING: A SAS Macro to Report Missing Value Percentages for a Multi-Year Multi-File Information System

S Y B Voc Software Development Syllabus

PharmaSUG Paper TT11

Paper An Automated Reporting Macro to Create Cell Index An Enhanced Revisit. Shi-Tao Yeh, GlaxoSmithKline, King of Prussia, PA

An Introduction to SAS University Edition

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Epidemiology Principles of Biostatistics Chapter 3. Introduction to SAS. John Koval

Procedure for Stamping Source File Information on SAS Output Elizabeth Molloy & Breda O'Connor, ICON Clinical Research

Techniques for Writing Robust SAS Macros. Martin Gregory. PhUSE Annual Conference, Oct 2009, Basel

Macro to compute best transform variable for the model

Basic Macro Processing Prepared by Destiny Corporation

SAS Graphs in Small Multiples Andrea Wainwright-Zimmerman, Capital One, Richmond, VA

The Basics of PROC FCMP. Dachao Liu Northwestern Universtiy Chicago

Get into the Groove with %SYSFUNC: Generalizing SAS Macros with Conditionally Executed Code

Seminar Series: CTSI Presents

Hot-deck Imputation with SAS Arrays and Macros for Large Surveys

Transcription:

Christopher Louden University of Texas Health Science Center at San Antonio

Overview of Macro Language Report Writing The REPORT procedure The Output Delivery System (ODS) Macro Examples Utility Macros A Macro for Categorical Variables A Macro for Continuous Variables Conclusion

To reduce programming time. To standardization programming. To declare constants (no magic numbers). data simulated; do i = 1 to 100; x = rannorm(123); output; end; run; %LET n_sims = 100; %LET seed = 123; data simulated; do I = 1 to &n_sims; x = rannorm(&seed); output; end; run;

The macros language provides the instructions. The macro processor does the work. Macro are based on text substitution in the code.

Two ways to declare %LET statement Used in open code. Known value. %LET n_sims = 200; call symput Used in data steps or PROC IML. Computed value (as a character). call symput( macro_var_name, value);

Reference macro variables with &. %LET test = chisq; %LET test = chisq; proc freq data = a; table x*y / &test; run; proc freq data = a; table x*y / chisq; run; Nested references use &&. %LET city = Cary; %LET state = NC; &&city._&state; &city._nc Cary_NC Note: the period after city denotes the end of the variable name (i.e. the variable is city not city_ ).

Advantages: Allow compartmentalization of code. Facilitate code reuse between programs. Reduce programming time. Decrease the number of programming errors. Limitations: Do not return values directly.

Called with %macro_name %my_macro1; Arguments can be passed to the macro. Positional arguments in order. %my_macro2(x, y, z); Keyword arguments proceeded by name. %my_macro3(x, arg2=z, arg3=y); %my_macro3(x, arg3=z, arg2=y); Arguments from within macro using &.

A macro to format p-values in a data step: %macro format_p_val(in, out); if missing(&in) then &out = ' '; else if 0.05 le &in lt 0.0505 then &out=compress('0.051'); else if 0.045 le &in lt 0.05 then &out=compress(round(&in,0.001)); else if 0 le &in lt 0.001 then &out=compress('<0.001'); else if 0.001 le &in lt 0.01 then &out=compress(round(&in,0.001)); else if 0.01 le &in le 1 then &out=compress(round(&in,0.001)); %mend format_p_val; Context: data pvalues; length cpvalue $6.; input npvalue; %format_p_val(npvalue,cpvalue); datalines;

If-else-if statements: %IF condition %THEN %DO; <statements> %END; %ELSE %DO; <statements> %END; Do statements (loops): %DO i = 1 %TO &max_iter; <statements> %END; System calls: %SYMEXIST(&macro_var_name);

Global can be used in anywhere in the code. Declared in open code. When the %global macro is used. Local can be used only in the macro in which the variable was declared. Declared in a macro function. Passed as an argument.

The REPORT procedure is a versatile tool for summarizing data. Can be used with ODS and PROC TEMPLATE to create well laid out tables.

The Output Delivery System (ODS) directs the output of procedures to different output streams. Use with statistical procedures to capture their output: ods trace on; ods output CrossTabFreqs = freqs; proc freq data = a; table x*y; run; ods trace off;

Use with procedures to direct the output to a file: options orientation = landscape number nodate; ods noproctitle; ods rtf body = "C:\Documents\Output.rtf" style = styles.lpg bodytitle; <Proc report statements> ods rtf close; Very powerful when used with templates

What will the data set need to look like? How do you get the pieces you need? What aspects might change from macro call to macro call?

The table is divided into panels. Label Group_1 Group_2 Total P_value Row Panel Age 0.003 1 1 N 193 203 396 2 1 Mean (SD) 52.4 (4.3) 51.3 (3.1) 51.8 (3.7) 3 1 SEM 0.3 0.2 0.2 4 1 Median [IQR] 51.9 [5.6] 51.2 [4.3] 51.4 [4.7] 5 1 Min, Max 43.7, 64.1 44, 59.2 43.7, 64.1 6 1

Summary Statistics The MEANS or UNIVARIATE procedures The FREQ procedure P-Values The GLM or NPAR1WAY procedures The FREQ procedure Panel Number Argument or Macro Counter

Parametric or Non-Parametric Tests Labels, Number of Groups Panel Number

Error Checking Gathering Statistics Manipulating Data Sets Clean Up (if desired)

Check parameters for bad values. data _NULL_; set _temp_contents; %LET _testerr = 1; if variable="&testvar" then call symput(_testerr, "0"); run; Use %RETURN or %GOTO. %IF _testerr="1" %THEN %GOTO TESTERR; <statements> %TESTERR: %PUT ERROR: Variable &testvar does not exist in data set &dat;

The %scan macro. Scans a macro variable and return the i th element. Elements separated by delimiter (default is space). %LET i=0; %DO %UNTIL (&_test=); %LET i=%eval(&i+1); %LET _test = %SCAN(&testvarlevels,&i); %END; %LET n_row=%eval(&i-1);

The FREQ procedure lists all the possible values for a variable in the data set. ods trace on; ods output OneWayFreqs = _names (keep=f_&classvar); proc freq data = &dat; table &classvar; run; ods trace off; %LET n_level = 0; data _NULL_; set _names; call symput('n_level',_n_); run;

The ODS output of the FREQ procedure has the names of the variables. %LET levels =; %DO i = 1 %TO &n_level; data _NULL_; set _names; if &i = _n_ then call symput(compress("clevel" "&i"),f_&classvar); run; %LET levels = &levels &&clevel&i; %END; %LET n_col=%eval(&i-1);

Use conditional programming to decide which test to use. Use ODS and the output statement to retrieve the statistics of interest as datasets.

Use of small temporary data sets facilitates the construction of the panel. P-value Summary Statistics Blank Line %scan macro to select the appropriate label. Set and Merge statements to combine them.

All temporary data set names begin with _. Use PROC DATASETS to delete them. proc datasets; delete _:; quit; The colon wildcard signifies every dataset beginning with _.

A global counter The date %macro initialize_counter(start=1); %global counter; %let counter = &start; %mend; %macro fdate(fmt); %global fdate; data _null_; call symput("fdate",trim(left(put("&sysdate9"d,&fmt)))); run; %mend fdate; %fdate(worddatx.);

Paginate the table %macro paginate(dat, foot=4, totalrows=22); Sorts the data by panel then row. Keeps a tally of the rows used on a page. Checks if a panel will fit on the page. If it can, the panel is assigned that page number. If not, the page number is incremented.

Error Check Parameters Determine Groups and Labels Gather Statistics Put Together Data Set