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

Similar documents
Reducing SAS Dataset Merges with Data Driven Formats

The Proc Transpose Cookbook

PROC FORMAT: USE OF THE CNTLIN OPTION FOR EFFICIENT PROGRAMMING

Merge Processing and Alternate Table Lookup Techniques Prepared by

PharmaSUG Paper TT11

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY

PharmaSUG 2013 CC26 Automating the Labeling of X- Axis Sanjiv Ramalingam, Vertex Pharmaceuticals, Inc., Cambridge, MA

Sorting big datasets. Do we really need it? Daniil Shliakhov, Experis Clinical, Kharkiv, Ukraine

An Efficient Method to Create Titles for Multiple Clinical Reports Using Proc Format within A Do Loop Youying Yu, PharmaNet/i3, West Chester, Ohio

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

SAS 101. Based on Learning SAS by Example: A Programmer s Guide Chapter 21, 22, & 23. By Tasha Chapman, Oregon Health Authority

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

A Tool to Compare Different Data Transfers Jun Wang, FMD K&L, Inc., Nanjing, China

Using GSUBMIT command to customize the interface in SAS Xin Wang, Fountain Medical Technology Co., ltd, Nanjing, China

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

Table Lookups: Getting Started With Proc Format

The Path To Treatment Pathways Tracee Vinson-Sorrentino, IMS Health, Plymouth Meeting, PA

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

An Efficient Tool for Clinical Data Check

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

PharmaSUG China Paper 70

The FORMAT procedure - more than just a VALUE statement Lawrence Heaton-Wright, Quintiles, Bracknell, UK

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

PharmaSUG Paper PO10

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

Formats, Informats and How to Program with Them Ian Whitlock, Westat, Rockville, MD

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

A SAS Solution to Create a Weekly Format Susan Bakken, Aimia, Plymouth, MN

Validation Summary using SYSINFO

PROC FORMAT. CMS SAS User Group Conference October 31, 2007 Dan Waldo

FSEDIT Procedure Windows

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

Macro Method to use Google Maps and SAS to Geocode a Location by Name or Address

Introduction. Understanding SAS/ACCESS Descriptor Files. CHAPTER 3 Defining SAS/ACCESS Descriptor Files

Paper PO06. Building Dynamic Informats and Formats

Application of Modular Programming in Clinical Trial Environment Mirjana Stojanovic, CALGB - Statistical Center, DUMC, Durham, NC

1. Join with PROC SQL a left join that will retain target records having no lookup match. 2. Data Step Merge of the target and lookup files.

Locking SAS Data Objects

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

SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC

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

FSVIEW Procedure Windows

Quality Control of Clinical Data Listings with Proc Compare

CHAPTER 7 Examples of Combining Compute Services and Data Transfer Services

Taming a Spreadsheet Importation Monster

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

Using the CLP Procedure to solve the agent-district assignment problem

Base and Advance SAS

Useful Tips When Deploying SAS Code in a Production Environment

Quick and Efficient Way to Check the Transferred Data Divyaja Padamati, Eliassen Group Inc., North Carolina.

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

Tales from the Help Desk 6: Solutions to Common SAS Tasks

Paper B GENERATING A DATASET COMPRISED OF CUSTOM FORMAT DETAILS

Loading Data. Introduction. Understanding the Volume Grid CHAPTER 2

Let SAS Write and Execute Your Data-Driven SAS Code

A SAS Macro for Generating Informative Cumulative/Point-wise Bar Charts

Gary L. Katsanis, Blue Cross and Blue Shield of the Rochester Area, Rochester, NY

An exercise in separating client-specific parameters from your program

using and Understanding Formats

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

It s not the Yellow Brick Road but the SAS PC FILES SERVER will take you Down the LIBNAME PATH= to Using the 64-Bit Excel Workbooks.

EXAMPLE 3: MATCHING DATA FROM RESPONDENTS AT 2 OR MORE WAVES (LONG FORMAT)

PharmaSUG China. Systematically Reordering Axis Major Tick Values in SAS Graph Brian Shen, PPDI, ShangHai

Uncommon Techniques for Common Variables

Exporting & Importing Datasets & Catalogs: Utility Macros

Format-o-matic: Using Formats To Merge Data From Multiple Sources

One-Step Change from Baseline Calculations

So, Your Data are in Excel! Ed Heaton, Westat

Basic SAS Hash Programming Techniques Applied in Our Daily Work in Clinical Trials Data Analysis

SAS Data Libraries. Definition CHAPTER 26

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

Amie Bissonett, inventiv Health Clinical, Minneapolis, MN

Regaining Some Control Over ODS RTF Pagination When Using Proc Report Gary E. Moore, Moore Computing Services, Inc., Little Rock, Arkansas

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China

Facilitate Statistical Analysis with Automatic Collapsing of Small Size Strata

A Format to Make the _TYPE_ Field of PROC MEANS Easier to Interpret Matt Pettis, Thomson West, Eagan, MN

Not Just Merge - Complex Derivation Made Easy by Hash Object

Checking for Duplicates Wendi L. Wright

PharmaSUG China Paper 059

Virtual Accessing of a SAS Data Set Using OPEN, FETCH, and CLOSE Functions with %SYSFUNC and %DO Loops

Using an ICPSR set-up file to create a SAS dataset

%MAKE_IT_COUNT: An Example Macro for Dynamic Table Programming Britney Gilbert, Juniper Tree Consulting, Porter, Oklahoma

Get SAS sy with PROC SQL Amie Bissonett, Pharmanet/i3, Minneapolis, MN

Missing Pages Report. David Gray, PPD, Austin, TX Zhuo Chen, PPD, Austin, TX

Advanced Tutorials. Paper More than Just Value: A Look Into the Depths of PROC FORMAT

Extending the Scope of Custom Transformations

I KNOW HOW TO PROGRAM IN SAS HOW DO I NAVIGATE SAS ENTERPRISE GUIDE?

PhUSE US Connect 2018 Paper CT06 A Macro Tool to Find and/or Split Variable Text String Greater Than 200 Characters for Regulatory Submission Datasets

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

Logging the Log Magic: Pulling the Rabbit out of the Hat

A SAS Macro to Generate Caterpillar Plots. Guochen Song, i3 Statprobe, Cary, NC

LST in Comparison Sanket Kale, Parexel International Inc., Durham, NC Sajin Johnny, Parexel International Inc., Durham, NC

How to Keep Multiple Formats in One Variable after Transpose Mindy Wang

Introduction. Getting Started with the Macro Facility CHAPTER 1

Paper # Jazz it up a Little with Formats. Brian Bee, The Knowledge Warehouse Ltd

Summary Table for Displaying Results of a Logistic Regression Analysis

STOP MERGING AND START COMBINING by Robert S. Nicol U.S. Quality Algorithms

New Vs. Old Under the Hood with Procs CONTENTS and COMPARE Patricia Hettinger, SAS Professional, Oakbrook Terrace, IL

Implementing external file processing with no record delimiter via a metadata-driven approach

The GEOCODE Procedure and SAS Visual Analytics

Transcription:

PharmaSUG 2011 - Paper TT02 Create a Format from a SAS Data Set Ruth Marisol Rivera, i3 Statprobe, Mexico City, Mexico ABSTRACT Many times we have to apply formats and it could be hard to create them specially if there are a lot of values to consider. But if you have all the values on a SAS data set you can pull them from there instead of creating the format manually (typing the data). This paper shows how to do that just by saying which variable you are going to use for the start of the range values (or a single value) and which value you want to receive back (a variable value or a pre-established value). INTRODUCTION The formats can be used for doing a lot of things; one useful application is having one format with a couple of values that can be matched with a data set (so you can avoid a merge statement). For example suppose that you have to show a listing which has 3 SAS data sets as source Let s see what the listing specification may look like: Listing of reactions during next five days after taken Medicine A. Patient Reactions.pat ient Type of reaction Reactions.reac_ type Day number Reactions. day Had it? Reactions.resp onse Maximum duration of reaction maxdur.max_ dur Did the patient decide to discontinue? discont.disconti nued 1 Pain 1 Yes 2 Yes 2 Yes 3 No 4 Yes Fever 1 No 1 2 No 3 No 4 Yes 2 Pain 1 No 1 No 2 No 3 Yes 4 No Fever 1 Yes 3 2 Yes 3 Yes 4 No Note: The response for Did the patient decide to discontinue? should only appear in the first row for each patient. 1

SAS data sets: Data set REACTIONS: Patient Reac_type response Day 1 PAIN YES 1 1 PAIN YES 2 1 PAIN NO 3 1 PAIN YES 4 1 PAIN NO 5 1 FEVER NO 1 1 FEVER NO 2 1 FEVER NO 3 1 FEVER YES 4 1 FEVER NO 5 2 PAIN NO 1 2 PAIN NO 2 2 PAIN YES 3 2 PAIN NO 4 2 PAIN NO 5 2 FEVER NO 1 2 FEVER NO 2 2 FEVER NO 3 2 FEVER NO 4 2 FEVER NO 5 Data set DISCONT: Patient Discontinued 1 YES 1 YES 2 NO 2 NO 2

POSSIBLE WAYS TO DO IT 1. With the traditional way (doing a merge) we would have to do this: 1 Do a PROC SORT to take care of duplicated records on REACTION and DISCONT datasets. 2 Merge these two data sets. proc sort data=reactions ; by patient reac_type response day; run; proc sort data=discont ; by patient discontinued; run; data all; merge reactions discont; by patient; run; Note that if we are not aware about duplicate records we can get this in the log: NOTE: MERGE statement has more than one data set with repeats of BY values. And we also get the new value on ALL records (instead of just one as we need for the listing). 3

2. Using a format you only need to do this (please see the complete macro code at the end of the paper on appendix A): 1 Create a format for DISCONT. 2 Use a simple data set statement to put the formatted values on the corresponding row. %doafmt ( fmtname=discon, dsn=discont, perm=n, end=, other=, print=n); start=patient, label=discon, type=n, It will create a format like this: And then just create the new variable with the value we want (in the place we want): data all; set reactions; if first.patient then discont=put(patient,discon.); run; And then we ll have our data set ready to be printed: 4

CONCLUSION This is the text for the paper s conclusion. When you are pulling a small amount of data, or even just one value, from multiple datasets, creating formats and using them in a simple DATA step statement can be easier than sorting them (taking care of duplicates), sometimes renaming the variables (when they have identical names on the different data sets) and merging them ( which involves checking that all the BY variables are correct). And talking about time-consuming- it s much more efficient to use a single DATA step with a PUT function than a data set MERGE, especially if we re dealing with thousands of records. ACKNOWLEDGMENTS Thank you to Nancy Brucken for her feedback when building this paper. I really appreciate it! CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Name: Ruth Marisol Rivera Enterprise: i3 Statprobe Address: Insurgentes Sur #416 4 th floor, Col Del Valle City, State ZIP: 03100, Mexico, DF Work Phone: 52(55) 5005 5525 E-mail: Marisol.rivera@i3statprobe.com 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. 5

APPENDIX A Code for the macro %doafmt. /* -------------------------------------------------------------------------- MACRO NAME: %doafmt DESCRIPTION: This macro creates a format from a SAS data set or view. USAGE: %doafmt( NAME, DSN, START=, LABEL=, TYPE=, PERM=, END=, OTHER=, PRINT= ); PARMS: - Required - NAME - Name of format. ( "$" not needed see "TYPE" below ). ( i.e.: MYFMT equates to $MYFMT for character formats or MYFMT for numeric formats. ) DSN - Name of SAS data set or view used to create format. Single level name assumes "work." ( i.e.: "sasuser.myfmt" pulls from libref "SASUSER" while "myfmt" pulls from "WORK." ) START - Name of the variable used for the start of the range values or single value. ( Left-of-equal-sign value ) ( i.e.: START=MODEL where MODEL is a variable on DSN ) LABEL - Name of the variable used for the formatted-value (label) or a quoted value. ( right-of-equal-sign value ) ( i.e.: LABEL=DESC where DESC is a variable on DSN or LABEL="YES" see selection example below ) - Optional _ TYPE - Type of format. N = Numeric Format P = Picture Format I = Numeric Informat C = Character Format ( Default ) J = Character Informat When type is "C" or "J" the resulting format is prefixed with a dollar sign ( $ ). PERM - Flag to create a permanent or temporary format. N = temporary format created. ( Default ) Y = permanent format created must have libref "LIBRARY" allocated via libname statement. END - Name of the variable used for the end of the range values. (left-of-equal-sign value ) OTHER - A quoted value for the OTHER option of formats. PRINT - Flag to print formats as they are created. N = Do not print format. ( Default ) Y = Print the format. EXAMPLES: %doafmt( myfmt, sasuser.myfmt, start=model, label=desc ); Generates a character format called "$myfmt" from dsn "sasuser.myfmt" using the variable "model" for range values and the variable "desc" for label values. %doafmt( myfmt, sasuser.myfmt, start=model, label="yes" ); Generates a character format called "$myfmt" from dsn "sasuser.myfmt" using the variable "model" for range values and assigns "YES" as label values constants. ------------------------------------------------------------------------- */ 6

%macro doafmt ( fmtname, dsn, start=, label=, type=c, perm=n, end=, other=, print=n ); %let type = %upcase( &type ); %let perm = %upcase( &perm ); %let print = %upcase( &print ); %let other = %quote( &other ); %if %substr( &fmtname, 1,1 ) eq %str($) %then %do; %let type = C; %let fmtname = %substr( &fmtname, 2 ); %end; DATA WORK._FMT_; /* create a dsn used on cntlin= of PROC FORMAT */ LENGTH START LABEL $200; RETAIN FMTNAME "&fmtname" TYPE "&type"; KEEP FMTNAME TYPE START LABEL %if &other ne %str( ) %then %str( HLO); %if &end ne %str( ) %then %str( END); %str(;); SET &dsn END=EOF; START = &start; %if &end ne %str( ) %then %str( END=&end;); LABEL = &label; OUTPUT; %if &other ne %str( ) %then %do; IF EOF THEN DO; START = 'OTHER'; LABEL = "&other"; HLO='O'; OUTPUT; END; %end; RUN; PROC SORT DATA=WORK._FMT_ NODUPKEY; /* remove dups on the start value */ by START; RUN; PROC FORMAT CNTLIN=WORK._FMT_ %if &perm eq %str(y) %then %str( LIBRARY=LIBRARY ); %if &print eq %str(y) %then %str( FMTLIB ); %str(;); RUN; %mend doafmt; 7