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

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

Uncommon Techniques for Common Variables

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

Quick Data Definitions Using SQL, REPORT and PRINT Procedures Bradford J. Danner, PharmaNet/i3, Tennessee

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

Data Quality Review for Missing Values and Outliers

CC13 An Automatic Process to Compare Files. Simon Lin, Merck & Co., Inc., Rahway, NJ Huei-Ling Chen, Merck & Co., Inc., Rahway, NJ

Programming & Manipulation. Danger: MERGE Ahead! Warning: BY Variable with Multiple Lengths! Bob Virgile Robert Virgile Associates, Inc.

Mapping Clinical Data to a Standard Structure: A Table Driven Approach

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

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

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

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

Paper S Data Presentation 101: An Analyst s Perspective

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

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

The Power of PROC SQL Techniques and SAS Dictionary Tables in Handling Data

Ditch the Data Memo: Using Macro Variables and Outer Union Corresponding in PROC SQL to Create Data Set Summary Tables Andrea Shane MDRC, Oakland, CA

Omitting Records with Invalid Default Values

Keeping Track of Database Changes During Database Lock

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

There s No Such Thing as Normal Clinical Trials Data, or Is There? Daphne Ewing, Octagon Research Solutions, Inc., Wayne, PA

Validation Summary using SYSINFO

Greenspace: A Macro to Improve a SAS Data Set Footprint

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

Open Problem for SUAVe User Group Meeting, November 26, 2013 (UVic)

Report Writing, SAS/GRAPH Creation, and Output Verification using SAS/ASSIST Matthew J. Becker, ST TPROBE, inc., Ann Arbor, MI

Prove QC Quality Create SAS Datasets from RTF Files Honghua Chen, OCKHAM, Cary, NC

WHAT ARE SASHELP VIEWS?

Checking for Duplicates Wendi L. Wright

Quality Control of Clinical Data Listings with Proc Compare

Macros for Two-Sample Hypothesis Tests Jinson J. Erinjeri, D.K. Shifflet and Associates Ltd., McLean, VA

ABSTRACT INTRODUCTION WORK FLOW AND PROGRAM SETUP

Know Thy Data : Techniques for Data Exploration

SAS Online Training: Course contents: Agenda:

An Efficient Tool for Clinical Data Check

Taming a Spreadsheet Importation Monster

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

A Macro to Create Program Inventory for Analysis Data Reviewer s Guide Xianhua (Allen) Zeng, PAREXEL International, Shanghai, China

Using Templates Created by the SAS/STAT Procedures

Data Manipulation with SQL Mara Werner, HHS/OIG, Chicago, IL

A Practical Introduction to SAS Data Integration Studio

Avoiding Macros in SAS. Fareeza Khurshed Yiye Zeng

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

Matt Downs and Heidi Christ-Schmidt Statistics Collaborative, Inc., Washington, D.C.

An Easier and Faster Way to Untranspose a Wide File

A Breeze through SAS options to Enter a Zero-filled row Kajal Tahiliani, ICON Clinical Research, Warrington, PA

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

Efficient Processing of Long Lists of Variable Names

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

Facilitate Statistical Analysis with Automatic Collapsing of Small Size Strata

Tracking Dataset Dependencies in Clinical Trials Reporting

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

How to Create Data-Driven Lists

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

Useful Tips When Deploying SAS Code in a Production Environment

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

Don t Forget About SMALL Data

SAS Linear Model Demo. Overview

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

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

PharmaSUG Paper SP07

Post-Processing.LST files to get what you want

Automating Preliminary Data Cleaning in SAS

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

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

Create Metadata Documentation using ExcelXP

The Dataset Diet How to transform short and fat into long and thin

PharmaSUG China 2018 Paper AD-62

Indenting with Style

The Power of Combining Data with the PROC SQL

%check_codelist: A SAS macro to check SDTM domains against controlled terminology

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

Programming Gems that are worth learning SQL for! Pamela L. Reading, Rho, Inc., Chapel Hill, NC

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

PharmaSUG Paper AD06

ODS TAGSETS - a Powerful Reporting Method

Paper DB2 table. For a simple read of a table, SQL and DATA step operate with similar efficiency.

Multiple Graphical and Tabular Reports on One Page, Multiple Ways to Do It Niraj J Pandya, CT, USA

An Introduction to Visit Window Challenges and Solutions

22S:172. Duplicates. may need to check for either duplicate ID codes or duplicate observations duplicate observations should just be eliminated

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

Adjusting for daylight saving times. PhUSE Frankfurt, 06Nov2018, Paper CT14 Guido Wendland

Let SAS Write and Execute Your Data-Driven SAS Code

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

100 THE NUANCES OF COMBINING MULTIPLE HOSPITAL DATA

PharmaSUG China Paper 059

A Few Quick and Efficient Ways to Compare Data

PharmaSUG Paper PO12

Using SAS software to fulfil an FDA request for database documentation

Using a Picture Format to Create Visit Windows

Two useful macros to nudge SAS to serve you

A SAS Macro for Producing Benchmarks for Interpreting School Effect Sizes

ABSTRACT INTRODUCTION TRICK 1: CHOOSE THE BEST METHOD TO CREATE MACRO VARIABLES

JMP and SAS : One Completes The Other! Philip Brown, Predictum Inc, Potomac, MD! Wayne Levin, Predictum Inc, Toronto, ON!

Macros to Report Missing Data: An HTML Data Collection Guide Patrick Thornton, University of California San Francisco, SF, California

From Manual to Automatic with Overdrive - Using SAS to Automate Report Generation Faron Kincheloe, Baylor University, Waco, TX

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

Know What You Are Missing: How to Catalogue and Manage Missing Pieces of Historical Data

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

Transcription:

How to Keep Multiple Formats in One Variable after Transpose Mindy Wang Abstract In clinical trials and many other research fields, proc transpose are used very often. When many variables with their individual formats are transposed into one variable, we lose the formats. We can do a series of if then statements to put the formats back in. However, when the variables involved are too many, the above method can be very tedious. This paper illustrates how to extract formats from dictionary.columns or sashelp.vcolumn, and then use PUTN function to assign the formats at run time and make the task much easier. In addition, it is much easier to apply the same method to other projects without a lot of hard coding in the SAS program. Efficiency is largely increased with this method Introduction Problems arise when transposing the different observations with different formats into one variable. It is impossible to have different formats for different observations for the same variable. Therefore the original formats do not show up at all after transpose. I have the following formats before transpose. proc format ; value sexcode 1 = 'Male ' 2 = 'Female' ; value racecode 1 = 'White' 2 = 'Black' 3 = 'Hipanic' 4 = 'Asian' 5 = 'Other' 6 = 'Multi-racial' ; data demo2; set desk.demo; format ; datestmp datetime17. birthdt mmddyy10. sexcd sexcode. racecd racecode. Following is the snapshot before the transpose. Please note that the sexcd and racecd variables display text formats.

Following is the snapshot after the transpose. Please note the sexcd and racecd now are numeric, instead of text.

If Then and Else Method There is some work to do to fix the problem. One way of doing it is to have a series of if then statements to accommodate value labels and hard code the value labels into a new variable. We can do it individually to each variable with format. Following is the codes that I used with this method. if upcase(compress(_name_))="datestmp" then do; n_value=put(col1, datetime17.); end; else if upcase(compress(_name_))="birthdt" then do; n_value=put(col1,mmddyy10. ); end; else if upcase(compress(_name_))="sexcd" then do; if Col1=1 then n_value= 'Male ' ; else if Col1=2 then n_value= 'Female' ; end; else if upcase(compress(_name_))="racecd" then do; if Col1=1 then n_value= 'White ' ; else if Col1=2 then n_value= 'Black' ; else if Col1=3 then n_value= 'Hipanic' ; else if Col1=4 then n_value= 'Asian' ; else if Col1=5 then n_value= 'Other' ; else if Col1=6 then n_value= 'Multi-racial' ; end; else n_value=col1;... Following is the snapshot after I used if then and else method.

While the method is working well with only a few variables with formats to be transposed, it becomes very tedious when the observations are in the hundreds or thousands. Extracting formats from Dictionary.Columns or Sashelp.Vcolumn and then applying PUTN function An easier way of doing it is to pull out the format information from dictionary.columns using sql, and then apply putn function to assign the individual format for each observation at run time. If you are not a sql person, you can do the same by pulling out format information from Sashelp.vcolumn. Following is the demonstration using dictionary.columns or sashelp.vcolumn then applying the formats using putn function. This method is much easier to adapt to other situations without a lot of hard coding. Following is where we can find the Sashelp.Vcolumn file.

You can use the following code to print the variable names and formats from Sashelp.Vcolumn. proc print data=sashelp.vcolumn noobs; where libname ='WORK' and memname='sample';

var name format; Following is the snapshot of the output window after running the above code. You can also export the Sashelp.Vcolumn file to excel if you are more familiar with Excel.

Following is the snapshot of the Excel file with all other data from Sashelp.Vcolumn except the sample file (that we are interested) filtered out.

Following is the code using proc sql. Then print the output file to Excel using ods tagsets.excelxp. proc transpose data=sample name=name out=t89 ; data Z89; set t89; seq+1; /*PULL OUT INFORMATION FROM DICTIONARY.COLUMNS*/ proc sql noprint; create table temp as select name, format from dictionary.columns where libname='work' and memname="sample" ; quit; /*PULL OUT INFORMATION FROM SASHELP.VCOLUMN*/ /*IT DOSE THE SAME AS THE ABOVE METHOD*/ /*UDE THIS ONE OR THE ABOVE SQL METHOD*/ data temp2; set sashelp.vcolumn; where libname ='WORK' and memname='sample'; keep name format; proc sort data=temp nodupkey; by name; proc sort data=z89; by name; data f89; length name $32.; merge Z89(in=a) temp; by name; if a; if format gt ' ' then value=putn(col1,format); if value=' ' then value=col1; proc sort data=f89; by seq; ods listing close; ods tagsets.excelxp file="desktop\data_for_visual_check.xls"; ods tagsets.excelxp options(sheet_name="id 89"); proc print data=f89 noobs ; where _label_ ^=' '; var _label_/style=[cellwidth=750]; var value /style=[cellwidth=300]; title1;

ods tagsets.excelxp close; ods listing; Following is the snapshot of the file after applying formats using PUTN function. Conclusions The latter method certainly makes your life easier. Not only it has minimized typing when the variables involved are too many, but is also more adaptable to other projects. It is always beneficial to write the programs that are easier to adapt to new situations, even though at first it takes time to develop, in the long run, it really saves time. Acknowledgement 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. Many thanks to SAS Technical Support for providing valuable suggestions in the developing of this paper. Contact Information Your comments and questions are valued and encouraged. Please contact the author at: Mindy Wang 14412 Stonebridge View Dr. North Potomac, MD 20878 Phone: (240) 855-3479 Email: ymindywang@yahoo.com