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

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

ERROR: ERROR: ERROR:

3/31/2016. Spreadsheets. Spreadsheets. Spreadsheets and Data Management. Unit 3. Can be used to automatically

Paper PO06. Building Dynamic Informats and Formats

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

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

Software Reference Sheet: Inserting and Organizing Data in a Spreadsheet

Introducing a Colorful Proc Tabulate Ben Cochran, The Bedford Group, Raleigh, NC

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

CHAPTER 4: MICROSOFT OFFICE: EXCEL 2010

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

Quality Control of Clinical Data Listings with Proc Compare

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

Using a Picture Format to Create Visit Windows

using and Understanding Formats

PROC REPORT Basics: Getting Started with the Primary Statements

BEYOND FORMAT BASICS 1

Formatting Highly Detailed Reports: Eye-Friendly, Insight-Facilitating

1. Introduction to Microsoft Excel

A Practical Introduction to SAS Data Integration Studio

A Simple Guide to Using SPSS (Statistical Package for the. Introduction. Steps for Analyzing Data. Social Sciences) for Windows

Make sure to keep all graphs in same excel file as your measures.

Paper S Data Presentation 101: An Analyst s Perspective

Merge Processing and Alternate Table Lookup Techniques Prepared by

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

Essentials of the SAS Output Delivery System (ODS)

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

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

Using Microsoft Excel

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

Arthur L. Carpenter California Occidental Consultants

BASIC MATH CONTENTS. Section 1... Whole Number Review. Section 2... Decimal Review. Section 3... Fraction Review. Section 4...

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

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

Excel for Auditors. by Bill Jelen and Dwayne K. Dowell. Holy Macro! Books

Stat Wk 3. Stat 342 Notes. Week 3, Page 1 / 71

SPSS: Basics & Entering a survey In this document the basic window of SPSS is explained and how to enter a survey.

proc print data=account; <insert statement here> run;

(Updated 29 Oct 2016)

Anyone Can Learn PROC TABULATE, v2.0

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

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

Welcome to Introduction to Microsoft Excel 2010

Microsoft Office Excel

Excel Tips for Compensation Practitioners Weeks Data Validation and Protection

One SAS To Rule Them All

Checklist. ORB Education Quality Teaching Resources. ORB Education Visit for the full, editable versions.

Intermediate SAS: Working with Data

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

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

Chapter 2 Assignment (due Thursday, April 19)

Beyond FORMAT Basics Mike Zdeb, School of Public Health, Rensselaer, NY

Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum)

The Proc Transpose Cookbook

Paper BB-59 PROC TRANSPOSE For Fun And Profit. John J. Cohen, Advanced Data Concepts, LLC

TIPS FROM THE TRENCHES

An Introduction to PROC REPORT

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

KEYWORDS Metadata, macro language, CALL EXECUTE, %NRSTR, %TSLIT

Let SAS Write and Execute Your Data-Driven SAS Code

THE EXCEL ENVIRONMENT... 1 EDITING...

Key concepts through Excel Basic videos 01 to 25

Excel Basics: Working with Spreadsheets

Accessing Data and Creating Data Structures. SAS Global Certification Webinar Series

44 Tricks with the 4mat Procedure

Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum)

Lab #9: ANOVA and TUKEY tests

ODS for PRINT, REPORT and TABULATE

Mathematics. Name: Class: Transforming Life chances

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

Gloucester County Library System EXCEL 2007

Biology 345: Biometry Fall 2005 SONOMA STATE UNIVERSITY Lab Exercise 2 Working with data in Excel and exporting to JMP Introduction

Gloucester County Library System. Excel 2010

Microsoft Excel 2010 Handout

CMU MSP : SAS FORMATs and INFORMATs Howard Seltman October 15, 2017

Basic Microsoft Excel Skills

Place Value. Unit 1 Lesson 1

WHOLE NUMBER AND DECIMAL OPERATIONS

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

Macros I Use Every Day (And You Can, Too!)

Excel Select a template category in the Office.com Templates section. 5. Click the Download button.

Excel Basic: Create Formulas

Language Editor User Manual

INFORMATION SHEET 24002/1: AN EXCEL PRIMER

Reducing SAS Dataset Merges with Data Driven Formats

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

Figure 3.20: Visualize the Titanic Dataset

BaSICS OF excel By: Steven 10.1

PharmaSUG China 2018 Paper AD-62

Advanced PROC REPORT: Doing More in the Compute Block

Homework 1 Excel Basics

PRACTICE EXERCISES. Family Utility Expenses

SAS Viewer giving way to Universal Viewer Steve Wright, Quintiles, RTP, NC

Week 6, Week 7 and Week 8 Analyses of Variance

Producing Summary Tables in SAS Enterprise Guide

National Child Measurement Programme 2017/18. IT System User Guide part 3. Pupil Data Management

Using Microsoft Excel to write SAS code Andrew Boyd, Quanticate, Edinburgh, UK

Part 1. Getting Started. Chapter 1 Creating a Simple Report 3. Chapter 2 PROC REPORT: An Introduction 13. Chapter 3 Creating Breaks 57

Table Lookups: From IF-THEN to Key-Indexing

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

Transcription:

Paper #1495-2014 Jazz it up a Little with Formats Brian Bee, The Knowledge Warehouse Ltd Abstract Formats are an often under-valued tool in the SAS toolbox. They can be used in just about all domains to improve the readability of a report, or be used as a look-up table to re-code your data. SAS, out of the box, includes a multitude of ready-defined formats that can be applied without modification to address most recode/re-display requirements; and if that s not enough, there is also a FORMAT procedure for defining your own custom formats. This paper will look at using some of the SAS-supplied formats in some innovative ways, but will primarily focus on the techniques we can apply in creating our own custom formats. Introduction The simplest way to improve the appearance of a report is to apply formats to the variables. The important thing to remember about applying a format is that the data value stored in the data set does not change. A format modifies the APPEARANCE of a variables VALUE. SAS-supplied formats The first group we should look at is the SAS-supplied formats. There are a multitude of them, but there is a small group that gets more use than most. The DOLLAR format is the first of this group used extensively across all business and industry sectors. Its purpose is to print a money amount with a dollar sign on the front, and commas separating the millions, thousands etc. Like many formats, modifying the overall width can produce quite different results value and I apply this format this is the result 12345.67 Dollar12.2 $12,345.67 12345.67 Dollar10.2 $12,345.67 12345.67 Dollar9.2 $12345.67 12345.67 Dollar8.2 12345.67 12345.67 Dollar7.2 12345.7 12345.67 Dollar5.2 12346 12345.67 Dollar4.2 12E3 Table1: The DOLLAR format Most of the date and datetime formats will display a similar behavior when the overall width is modified, giving different representations of dates and times eg 2- vs 4-digit years, full vs abbreviated monthname etc.

There are also several lesser known formats that can be brought into more common usage. The Z. format will print a numeric value without suppressing leading zeros which is the default with the DOLLAR and COMMA formats. This is used often for printing account numbers or id numbers of various sorts. The ROMAN format will print a numeric value in roman numerals. An interesting way of printing page numbers! Note it does not print decimals. One that is used less frequently these days is the WORDS format. This prints a numeric value in words rather than digits. A common usage was writing cheques! value.. And I apply this format. this is the result 1234.5 Z8.1 001234.5 1234.5 Roman12. MCCXXXIV 1234.5 Words60. one thousand two hundred thirty-four and fifty hundredths Table 2: Selected formats A new date format DTDATE has proved to be very useful. This will print just the date portion of a date-time value. Prior to the introduction of this format, the DATEPART function would need to be used to separate off the date, and then format the result. value.. And I apply this format. this is the result '23jul1999:12:34:56'dt Dtdate5. 23JUL '23jul1999:12:34:56'dt Dtdate7. 23JUL99 '23jul1999:12:34:56'dt Dtdate9. 23JUL1999 '23jul1999:12:34:56'dt Dtdate. 23JUL99 Table 3: the DTDATE format The FORMAT procedure When we are faced with the situation of not being able to find a format that does the job exactly as we want, then we have the format procedure to help us out. There are three important statements that we can use in the format procedure : the value, invalue and picture statements.

VALUE statement. This one is reasonably well known, but not fully utilized. The simplest form is a series of single values, formatted to labels. Eg F = Female M = Male or 1= One 2= More. Next we can specify ranges of values eg low-10= Young 11-13= Mid 14-high= Older. LOW and HIGH are special values we can use to represent The lowest possible value and The highest possible value respectively. We can also have lists of values eg 2,3,4,5,6= Weekday 1,7= Weekend. And lastly we can have multiple formats! Eg.= missing other=[ages.]. For example: proc format; value $gender value ages 'M'='Male' 'F'='Female'; low-10='young' 11-13='Mid' 14-high='Older'; value weeks 2,3,4,5,6='Weekday' 1,7='Weekend'; value multi.='missing' other=[ages5.]; In the last value statement, a missing value returns the word Missing and all other values have the AGES5. format applied. value.. And I apply this format. this is the result F $gender Female 27 Ages. Older 4 Weeks. Weekday 12 Multi. Mid. Multi. Missing Table 4: Using the VALUE statement INVALUE statement This one is invaluable when we are validating data either from a dataset or a raw data file. It allows us to preserve values if they are valid, or change them if they are not. For example:

proc format; invalue group 1-100=_same_ other=.; invalue num 'A' - 'M' = 1 'N' - 'Z' = 2 1-100 = 3; invalue nume 1-10=_same_ 99=. other=_error_; In the last invalue statement, values 1-10 remain the same, 99 returns a missing value, and all other values cause the automatic variable _ERROR_ to be set to 1. The invalue statement is effectively creating informats, and they are applied in the usual manner eg input smallnums nume. etc; value.. And I apply this informat. this is the result 77 Group. 77 326 Group.. J Num. 1 12 Num. 3 99 Nume.. 45 Nume. _ERROR_ set to 1 Table 5: Using the INVALUE statement PICTURE Statement This is where we get maximum utility from PROC FORMAT. If you are required to print a numeric value a certain way, and you just can t find a SAS-supplied format to do it, and value and invalue statements don t help, then the PICTURE statement comes to the rescue. The PICTURE statement allows us to define a print template for printing numeric values, including text. A common requirement here is where we want a report with a column heading Total (in Millions) and the values taken from our dataset displayed simply as, say, 16, representing 16million. So using the PICTURE statement we specify how we want the number represented, and include a multiplier of.000001 in this example. The value from the dataset is multiplied by the multiplier, and then the print template is applied to the result. A prefix can also be included, for example a $ sign, and there is a NOEDIT option where the label includes numeric values which should not be considered print directives. Another use is where there is a requirement to print a date in an unusual way that is not covered by any of the date/datetime formats. There is a series of directives that can be used to represent all the different elements of dates and times. For example the string %d(%a)*%b*%y(%h:%m:%s) would cause a datetime value to be printed like 01(Wednesday)*January*2012(01:11:03).

When specifying a print template the directives are used to identify what characters should be returned. 0 - when leading zeros are included in the value, suppress them 1-9 - when leading zeros are included in the value, print them. EG a picture of 0009.99 will suppress leading zeroes in the first 3 positions and will print a value for the 4 th digit even if it is a zero. Directives 1 thru 9 can be used. Common usage is to use 0 s and 9 s. For example: proc format; picture mills low-high='0009.99m' (mult=.000001); picture millsp picture mydate other='0009.99m' (mult=.000001 prefix='$'); other='0%d(%a)*%b*%y(%h:%m:%s)' (datatype=datetime); picture big 1-1000 = '0009' 1000<-high = '>1000km' (noedit); If my variable contains this value.. And I apply this this is the result format. 23945123 Mills. 23.95M 614339 Mills. 0.61M 23945123 Millsp $23.95 05jun2001:12:34:56 Mydate. 05(Tuesday)*June*2001(12:34:56) 633 Big. 633 1874 Big. >1000km Table 6: Using the PICTURE statement CNTLIN option The CNTLIN option allows PROC FORMAT to read data from a dataset and use it to build a format. This becomes very useful when the information in the format changes on a regular basis it saves you having to modify a program each time it has to be updated.the dataset being read must conform to certain rules in that it must contain the following variables A character variable called FMTNAME that contains the name that should be assigned to the format A variable called START that contains the range A character variable called LABEL that contains the label for the range For example:

A dataset to create the GENDER format illustrated earlier should look like.. FMTNAME START LABEL $GENDER F Female $GENDER M Male Table 7: Single values in the format A dataset to create the num format illustrated above should include an extra column named END and look like FMTNAME START END LABEL NUMS A M 1 NUMS N Z 2 NUMS 1 100 3 Table 8: Ranges in the format The dataset can also be created from an existing dataset. For example Data control; Set incoming; retain fmtname nums ; Rename gender=start description=label; *an assignment statement or an expression can be used instead; The dataset can now be read into the FORMAT procedure thus Proc format cntlin=control; Conditional highlighting Conditional highlighting otherwise known as Traffic lighting - involves using colour to highlight data values. This is something that has in the past often been accomplished by exporting the data out to other reporting software and then going through the report manually modifying the appearance cell by cell. So step one of the SAS solution is to create a format that defines the ranges or values you want highlighted, and assign a label that specifies a colour to each range of values. Proc format; Value ranges 0-62 = 'Blue' 62< - 63 = 'Red' Other = 'Green'; Run;

Step two is to generate your report. PROC REPORT lends itself very nicely to this application and is very simple to modify. Once the basic report is created and fine tuned, you can modify the code to implement the traffic-lighting. The changes that need to be made involving adding a style statement to the line that defines the variable you want to apply your traffic-lighting to. proc report data=sashelp.class nowd; column name sex age height; define name / group 'Name' missing; compute name; if name ne ' ' then hold1=name; if name eq ' ' then name=hold1; endcomp; define sex / group 'Sex' missing; compute sex; if sex ne ' ' then hold2=sex; if sex eq ' ' then sex=hold2; endcomp; define age / analysis SUM 'Age' missing; define height / analysis SUM 'Height' missing style(column) = [background=ranges. foreground=white]; Run; The key to the whole process is expressing the ranges FORMAT for the background, and white for the foreground to give white text. The obvious alternative is to use the format for the foreground and leave the background unchanged. This will return coloured text on a white background.

Traffic-lighting is a far simpler process than most people imagine. For a fuller description of this subject, see Paper 273-2009 Traffic-Lighting Your Reports the Easy Way with PROC REPORT and ODS. by Andrew Karp. This excellent paper was presented at SAS Global Forum 2009, and explores several different options for traffic-lighting. Summary In using formats you are restricted only by your imagination. You can take any value and apply a format to it where the format is re-presenting the value as absolutely anything you can type on your keyboard (and more). It is generally a very simple method of jazzing up your report to take it from ordinary to a work of art!

Author contact Brian Bee The Knowledge Warehouse Limited P.O. Box 10-541 The Terrace Wellington New Zealand +64 21 630075 Brian.Bee@knoware.co.nz Copyright SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the United States of America and other countries. indicates USA registration. Other brand or product names are registered trademarks of their respective companies.