Document and Enhance Your SAS Code, Data Sets, and Catalogs with SAS Functions, Macros, and SAS Metadata. Louise S. Hadden. Abt Associates Inc.

Similar documents
Document and Enhance Your SAS Code, Data Sets, and Catalogs with SAS Functions, Macros, and SAS Metadata

What to Expect When You Need to Make a Data Delivery... Helpful Tips and Techniques

PROC DOC III: Self-generating Codebooks Using SAS

Better Metadata Through SAS II: %SYSFUNC, PROC DATASETS, and Dictionary Tables

PROC CATALOG, the Wish Book SAS Procedure Louise Hadden, Abt Associates Inc., Cambridge, MA

SAS. IT Service Level Management 2.1: Migration Documentation

Extending the Scope of Custom Transformations

A Mass Symphony: Directing the Program Logs, Lists, and Outputs

Give me EVERYTHING! A macro to combine the CONTENTS procedure output and formats. Lynn Mullins, PPD, Cincinnati, Ohio

PROC DOC III: Self-generating Codebooks Using SAS

Useful Tips When Deploying SAS Code in a Production Environment

Transitioning from Batch and Interactive SAS to SAS Enterprise Guide Brian Varney, Experis Business Analytics, Portage, MI

The 'SKIP' Statement

Patricia Guldin, Merck & Co., Inc., Kenilworth, NJ USA

Automating Comparison of Multiple Datasets Sandeep Kottam, Remx IT, King of Prussia, PA

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

Storing and Reusing Macros

Speed Dating: Looping Through a Table Using Dates

SAS ENTERPRISE GUIDE USER INTERFACE

SAS File Management. Improving Performance CHAPTER 37

Purchase this book at

SAS Online Training: Course contents: Agenda:

Getting Up to Speed with PROC REPORT Kimberly LeBouton, K.J.L. Computing, Rossmoor, CA

My SAS Grid Scheduler

Product Manager Toolkit

A Practical Introduction to SAS Data Integration Studio

Using the SQL Editor. Overview CHAPTER 11

Exporting Variable Labels as Column Headers in Excel using SAS Chaitanya Chowdagam, MaxisIT Inc., Metuchen, NJ

What Is SAS? CHAPTER 1 Essential Concepts of Base SAS Software

Using SAS/SCL to Create Flexible Programs... A Super-Sized Macro Ellen Michaliszyn, College of American Pathologists, Northfield, IL

Call: SAS BI Course Content:35-40hours

Functions vs. Macros: A Comparison and Summary

One SAS To Rule Them All

Paper A Simplified and Efficient Way to Map Variable Attributes of a Clinical Data Warehouse

Files Arriving at an Inconvenient Time? Let SAS Process Your Files with FILEEXIST While You Sleep

Using a Control Dataset to Manage Production Compiled Macro Library Curtis E. Reid, Bureau of Labor Statistics, Washington, DC

The Impossible An Organized Statistical Programmer Brian Spruell and Kevin Mcgowan, SRA Inc., Durham, NC

TIPS AND TRICKS: IMPROVE EFFICIENCY TO YOUR SAS PROGRAMMING

Easing into Data Exploration, Reporting, and Analytics Using SAS Enterprise Guide

Taming a Spreadsheet Importation Monster

Best Practice for Creation and Maintenance of a SAS Infrastructure

Parallelizing Windows Operating System Services Job Flows

APPENDIX 4 Migrating from QMF to SAS/ ASSIST Software. Each of these steps can be executed independently.

Interactive Programming Using Task in SAS Studio

Planting Your Rows: Using SAS Formats to Make the Generation of Zero- Filled Rows in Tables Less Thorny

Using a Fillable PDF together with SAS for Questionnaire Data Donald Evans, US Department of the Treasury

Paper HOW-06. Tricia Aanderud, And Data Inc, Raleigh, NC

Create Metadata Documentation using ExcelXP

Moving Data and Results Between SAS and Excel. Harry Droogendyk Stratia Consulting Inc.

Remodeling Your Office A New Look for the SAS Add-In for Microsoft Office

Chasing the log file while running the SAS program

PharmaSUG Paper AD06

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

Using SAS to Control and Automate a Multi SAS Program Process Patrick Halpin, dunnhumby USA, Cincinnati, OH

SAS Data Integration Studio Take Control with Conditional & Looping Transformations

WHAT ARE SASHELP VIEWS?

Dictionary.coumns is your friend while appending or moving data

SESUG 2014 IT-82 SAS-Enterprise Guide for Institutional Research and Other Data Scientists Claudia W. McCann, East Carolina University.

Automation of makefile For Use in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

Paper SAS Managing Large Data with SAS Dynamic Cluster Table Transactions Guy Simpson, SAS Institute Inc., Cary, NC

Create a Format from a SAS Data Set Ruth Marisol Rivera, i3 Statprobe, Mexico City, Mexico

Run your reports through that last loop to standardize the presentation attributes

Creating a Departmental Standard SAS Enterprise Guide Template

Data Edit-checks Integration using ODS Tagset Niraj J. Pandya, Element Technologies Inc., NJ Vinodh Paida, Impressive Systems Inc.

An Automation Procedure for Oracle Data Extraction and Insertion

Data Presentation ABSTRACT

Same Data Different Attributes: Cloning Issues with Data Sets Brian Varney, Experis Business Analytics, Portage, MI

PREREQUISITES FOR EXAMPLES

How to Create Data-Driven Lists

MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL

Application Interface for executing a batch of SAS Programs and Checking Logs Sneha Sarmukadam, inventiv Health Clinical, Pune, India

Automated Checking Of Multiple Files Kathyayini Tappeta, Percept Pharma Services, Bridgewater, NJ

What's the Difference? Using the PROC COMPARE to find out.

Real Time Clinical Trial Oversight with SAS

Paper CC16. William E Benjamin Jr, Owl Computer Consultancy LLC, Phoenix, AZ

Getting Started with Composer 2

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

The Ins and Outs of %IF

Exporting Access Databases with Indexes and Keys Roger S. Cohen, New York State Dept of Tax and Finance, Albany, New York

SAS/Warehouse Administrator Usage and Enhancements Terry Lewis, SAS Institute Inc., Cary, NC

APPENDIX 2 Customizing SAS/ASSIST Software

SAS Information Map Studio 2.1: Tips and Techniques

A Guided Tour Through the SAS Windowing Environment Casey Cantrell, Clarion Consulting, Los Angeles, CA

SAS Information Map Studio 3.1: Tips and Techniques

Paper ###-YYYY. SAS Enterprise Guide: A Revolutionary Tool! Jennifer First, Systems Seminar Consultants, Madison, WI

Troy Martin Hughes ABSTRACT INTRODUCTION

How to design and print cards using a database connection with. emedia CS Software

A Methodology for Truly Dynamic Prompting in SAS Stored Processes

Using Metadata Queries To Build Row-Level Audit Reports in SAS Visual Analytics

An Efficient Tool for Clinical Data Check

PharmaSUG China 2018 Paper AD-62

This document is being provided for training purposes and is subject to further edits, corrections and/or modifications.

How to use UNIX commands in SAS code to read SAS logs

Improving Your Relationship with SAS Enterprise Guide Jennifer Bjurstrom, SAS Institute Inc.

SAS Data Integration Studio 3.3. User s Guide

Paper Phil Mason, Wood Street Consultants

Producing Summary Tables in SAS Enterprise Guide

PDF Multi-Level Bookmarks via SAS

Introduction Accessing MICS Compiler Learning MICS Compiler CHAPTER 1: Searching for Data Surveys Indicators...

SAS Data Libraries. Definition CHAPTER 26

Transcription:

Document and Enhance Your SAS Code, Data Sets, and Catalogs with SAS Functions, Macros, and SAS Metadata Louise S. Hadden Abt Associates Inc. Louise Hadden has been using and loving SAS since the days of punch cards and computers the size of a tiny house. She spends most of her time in support of health policy analytics at Abt Associates Inc. and loves a good SAS reporting challenge. She is an ardent life long learner and reads voraciously, loves photography and volunteers at the MSPCA Boston Adoption Center walking, training and photographing dogs.

Document and Enhance Your SAS Code, Data Sets, and Catalogs with SAS Functions, Macros, and SAS Metadata SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are trademarks of their respective companies.

Paper 1314-2017 Document and Enhance Your SAS Code, Data Sets, and Catalogs with SAS Functions, Macros, and SAS Metadata Louise Hadden and Roberta Glass, Abt Associates Inc. Use SAS System Macros Introduction Stored Header Macro Information at your fingertips: when a program was last run; who ran it; what variables were created; whether the data set is sorted or indexed ; whether a program was run interactively or in batch mode and more! Some examples: path and program name (batch mode): %SYSFUNC(GETOPTION (SYSIN)); path and program name (interactive): %SYSGET(SAS_EXECFILEPATH); date the program began: &SASDATE time the program began: &SYSTIME programmer who submitted the job: &SYSUSERID batch / interactive: &SYSPROCESSMODE condition code: &SYSCC Ways to use: Link output and logs to program creating them Create variable indicating program creating a data set (or other useful information) Label your data sets Tip: Use PROC DATASETS to put a label on your data sets after the fact By using SAS metadata in conjunction with automated documentation, you can find out when a program was last run, who ran it, what variables were created, whether the data set is sorted or indexed, and more. You can use your metadata to write portions of your programs, and to generate codebooks. We will give you a whirlwind tour of tools, tips and techniques to enhance your SAS programming toolkit! There are many more SAS system macros and many other uses of %SYSFUNC please check the SAS documentation, papers by Kathy Fraeman or Troy Martin Hughes book SAS Data Analytic Development: Dimensions of Software Quality to get some other ideas. A simple macro can insure that every program log has a header section which contains essential information. First, save a compiled version of the macro to a macro catalog. Insert the macro code in every program you or your team writes Your log will show the program header automatically. TIP: you can store a description of your macro when creating it using the DES= option.

Autodoc Macro: Automatically Create and Modify a Processing Log Save an empty Microsoft Excel file log before using the macro the first time. Begin creating a macro, specify where to store it, and describe it. %MACRO autodoc(docfile) / STORE SOURCE DES="Creates program log"; You can place code at the top of your macro which will prompt users to enter information before executing the rest of the code. What is entered is collected as macro variables. %window info #4 @5 'Please enter the purpose of this program:' #5 @5 purpose 50 attr=underline display=yes auto=no color = blue... %display info; %put &purpose ; The macro will generate a line for each program run, using information from program prompts and system macros. Import the old spreadsheet, create a backup, then append the new line onto the original dataset. PROC IMPORT DBMS = excel OUT = backupdoca DATAFILE = "&docfile."; DATA backupdoc; LENGTH &lengths.; SET backupdoca; PROC APPEND DATA=userline BASE=backupdoc FORCE; Create a permanent updated file, then export that information and update the existing program log spreadsheet. The file can easily be opened, additional notes added, and re-saved. DATA doc.backupdoc; SET backupdoc; PROC EXPORT data= doc.backupdoc OUTFILE = "&docfile." DBMS=EXCEL LABEL REPLACE; SHEET="program log"; %MEND; DATA userline;... run_by="&sysuserid"; run_date="&sysdate"; run_time="&systime"; purpose="&purpose";

Codebook Generation: Self-writing Programs Steps for the example discussed in the paper: Create a modified copy of SASHELP.HEART, and produce an Excel spreadsheet by exporting PROC CONTENTS output. In our case, we write out text files using data _null_ which call different macros for different types of variables and different desired outputs (headers for variables, descriptors for variables, detail for variables.) General concepts regarding reporting in this context: PROC REPORT and PROC TEMPLATE can handle SAS paragraphs (really long text fields) Create a NOBORDER style template Stack headers, descriptors and detail in a paragraph for each variable to be documented Review the documentation spreadsheet, modify (if needed), and re-import the modified spreadsheet into SAS. General concepts regarding self-writing programs: SAS programs are text files SAS can create, modify and read text files SAS character functions (the fabulous feline CAT functions) make it possible to create paragraphs

Other Uses of the Codebook Generation Program Conclusion Documenting SAS Catalogs Similarly, metadata can be accessed to create label, format, and length, etc. statements. The resulting statements can be included in other programs seamlessly. Use SAS metadata, system macros and processes to: Automatically generate a program header Keep a processing log up-to-date Label your data sets, variables, and catalog entries Identify the code that created datasets,.logs,.lsts, and tables Generate components of your SAS programs without typing a word - and more! Create user-friendly documentation And more! General concepts: Save format libraries with specific, two-level names: LIBNAME Fmtlib "C:\...\Fmtlib"; PROC FORMAT LIBRARY = fmtlib.test; VALUE $trtmt 'C' = "Control" 'T' = "Treatment Other = "Error"; To use a saved named format, specify the format library in the options statement. OPTIONS MSTORED FMTSEARCH = (Fmtlib.test); Descriptions for formats can be added using a PROC CATALOG MODIFY statement. Contact us! Your comments and questions are valued and encouraged. Contact the authors at: Roberta Glass Roberta_Glass@abtassoc.com Louise Hadden Louise_Hadden@abtassoc.com Scan me! Sample code available: Descriptions for macros (and other catalogs other than formats) can be added using the DES option while creating the catalog entry: %MACRO autodoc(docfile)/ STORE SOURCE DES="Creates program log"; Similarly, you can add descriptions to macro (or graphic, or other) catalogs with a PROC CATALOG MODIFY statement. Adding these descriptions can save you a lot of time at the end of a project (and during it).

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are trademarks of their respective companies.