FORMAT FESTIVAL AN INTRODUCTION TO SAS® FORMATS AND INFORMATS By David Maddox.

Slides:



Advertisements
Similar presentations
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Advertisements

Chapter 17 Read Raw Data in Fixed Format using Formatted Input Objectives Distinguish between standard and nonstandard numeric data Read standard fixed-field.
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
PROC_CODEBOOK: An Automated, General Purpose Codebook Generator
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Into to SAS ®. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Introduction to SAS Lecture 2 Brian Healy.
Creating SAS® Data Sets
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Copyright © 2006, SAS Institute Inc. All rights reserved. Randy Poindexter & Scott Huntley Output Delivery and Reporting An Introduction to ODS.
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks.
A Concise Display of Multiple Response Items Patrick Thornton.
SAS PROC REPORT PROC TABULATE
Lecture 5 Sorting, Printing, and Summarizing Your Data.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Niraj J. Pandya, Element Technologies Inc., NJ.  Summarize all possible combinations of class level variables even if few categories are altogether missing.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina Chapter 17 supplement: Review of Formatting Data STAT 541.
Prepared by: Luigi Muro – Consultant
My ODS: Real-World Uses of Modifying Table Templates Steve James Centers for Disease Control and Prevention Atlanta, Ga.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
BMTRY 789 Lecture 2 SAS Syntax, entering raw data, etc. Lecturer: Annie N. Simpson, MSc. Readings – Chapters 1, 2, 12, & 13 Lab Problems 1.1, 1.2, 1.3,
I OWA S TATE U NIVERSITY Department of Animal Science Getting Your Data Into SAS (Chapter 2 in the Little SAS Book) Animal Science 500 Lecture No. 3 September.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
Using the new Version 8 Template Procedure for Complete Control of SAS Output Style and Format David Ghan Technical Training Specialist SAS, Canada.
Summer SAS Workshop Lecture 2. Summer Summer SAS Workshop Lecture 2 I’ve got Data…how do I get started? Libname Review How do you do arithmetic.
Formats to the Rescue Gary McQuown Data and Analytic Solutions Inc. Fairfax, VA.
Chapter 5 Reading and Manipulating SAS ® Data Sets and Creating Detailed Reports Xiaogang Su Department of Statistics University of Central Florida.
Creating and Using Custom Formats for Data Manipulation and Summarization Presented by John Schmitz, Ph.D. Schmitz Analytic Solutions, LLC Certified Advanced.
PROC FORMAT – Not Just Another Pretty Face. PROC FORMAT, because of its name, is most often used to change the appearance of data for presentation. But.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
1 EPIB 698C Lecture 4 Raul Cruz-Cano Summer 2012.
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming Data Input in SAS Many ways to get your data into SAS: –Through data entry.
SAS for Data Management and Analysis
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
Copyright © 2004, SAS Institute Inc. All rights reserved. SASHELP Datasets A real life example Barb Crowther SAS Consultant October 22, 2004.
Chapter 18 Reading Free-Format Data. 2 Objectives Read free-format data not recognized in fixed fields. Read free-format data separated by non-blank delimiters,
Customize SAS Output Using ODS Joan Dong. The Output Delivery System (ODS) gives you greater flexibility in generating, storing, and reproducing SAS procedure.
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
SAS Certification Prep Guide Chapter 7 Creating and Applying User-Defined Formats.
Copyright 2009 The Little Engine That Could: Using EXCEL LIBNAME Engine Options to Enhance Data Transfers between SAS® and Microsoft® Excel Files William.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
Applied Business Forecasting and Regression Analysis
Instructor: Raul Cruz-Cano 7/9/2012
Chapter 2: Getting Data into SAS
SAS Programming Introduction to SAS.
Chapter 4: Sorting, Printing, Summarizing
PROC DOC III: Self-generating Codebooks Using SAS®
WEB PROGRAMMING JavaScript.
Creating Macro Variables in the DATA Step
Hans Baumgartner Penn State University
Login Main Functions Via SAS Information Delivery Portal
Presentation transcript:

FORMAT FESTIVAL AN INTRODUCTION TO SAS® FORMATS AND INFORMATS By David Maddox

FORMAT FESTIVAL Formats and Informats - powerful SAS® language components. Format - an instruction or template that SAS uses to output data values. Informat - an instruction or template for reading data values.

FORMAT FESTIVAL There are two basic types of Informats – SAS® Supplied and User Created. Character Informats have the form - $ w. Examples - $char7., $hex4.

FORMAT FESTIVAL Numeric Informats omit the “$” sign and may include a decimal width. Examples of numeric Informats are: comma7.2 – removes embedded commas and $ signs. pd4. – Reads packed decimal

FORMAT FESTIVAL Date Informats are used to convert date and time information into a SAS® date format. A SAS date is a number which represents the number of days since January 1, Examples of date Informats are: mmddyy10. – 10/09/2006 date11. – 09/OCT/2006

FORMAT FESTIVAL Specifying Informats for use in a program. - INPUT Statement - INPUT, INPUTC, INPUTN Functions - INFORMAT Statement - ATTRIB Statement

FORMAT FESTIVAL Example 1 – Using an Informat to read in a variable. 03/01/2002 $1,035, /04/2002 $1,075, /05/2002 $1,236, /06/2002 $1,422, /07/2002 $1,635, /08/2002 $1,880, /11/2002 $2,162, /12/2002 $2,487, /13/2002 $2,860, /14/2002 $3,289, /15/2002 $3,782, /18/2002 $4,350, /19/2002 $5,002,767.

FORMAT FESTIVAL data ex1; Infile 'c:\Workshop\HW07\Data\ex1.txt; input datev mmddyy10. revenue comma12.; run;

FORMAT FESTIVAL Example 2 – Creating and using a user defined Informat. - PROC FORMAT is used to create user-defined Formats and Informats - Use an INFORMAT or ATTRIB statement to permanently associate a variable and an Informat

FORMAT FESTIVAL proc format; invalue $ganpa '229'='Albany' '706','762'='Athens' '404','470','678','770'='Atlanta' '478'='Macon' '912'='Savannah'; run; data ex2; length npa $8; input npa $ganpa3. nxx $ 4-6 line $ 7-10 revenue 12.2; cards; AAAA XXXX BBBB CCCC DDDD EEEE FFFF GGGG HHHH31.2 ; run;

FORMAT FESTIVAL Obsnpanxxlinerevenue 1Atlanta423AAAA50 2Albany543XXXX75 3Savannah333BBBB25 4Savannah767CCCC Atlanta221DDDD46 6Macon332EEEE34.5 7Atlanta681FFFF21.7 8Athens728GGGG45.8 9Albany476HHHH31.2

FORMAT FESTIVAL Example 3 – Creating a permanent user defined Informat -Reference the catalog using PROC FORMAT Library= option. -Use LIBNAME to declare a FORMATS catalog

FORMAT FESTIVAL proc format library=library; invalue $ganpa '229'='Albany' '706','762'='Athens' '404','470','678','770'='Atlanta' '478'='Macon '912'='Savannah'; run; proc format library=library fmtlib; run; The FMTLIB produces the following information about the $ganpa. INFORMAT. This option can be used to check the user created INFORMAT for accuracy and completeness.

FORMAT FESTIVAL | INFORMAT LENGTH: 8 NUMBER OF VALUES: 9 MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH 8 FUZZ: 0 | |START |END |INVALUE(VER. V7|V8 04JUL2006:18:25:37)| | |229 |229 |Albany |404 |404 |Atlanta |470 |470 |Atlanta |478 |478 |Macon |678 |678 |Atlanta |706 |706 |Athens |762 |762 |Athens |770 |770 |Atlanta |912 |912 |Savannah

FORMAT FESTIVAL Example 4 – Using a Format to print a variable - PUT Statement - PUT, PUTC, PUTN Functions - %SYSFUNC macro function - FORMAT Statement - ATTRIB Statement

FORMAT FESTIVAL libname ds 'c:\Workshop\HW07\Datasets'; proc print data=ds.ex1; run; proc print data=ds.ex1; format datev mmddyy10. revenue comma12.; run; proc print data=ds.ex1; format datev mmddyy7. revenue dollar14.2; run; proc print data=ds.ex1; format datev date7. revenue euro12.; run; proc print data=ds.ex1; format datev worddate12. revenue e12.; run; data _null_; set ds.ex1; file print; put datev date9. +1 revenue comma14.2; run;

FORMAT FESTIVAL Example 5 – Creating and using a user defined Formats - PROC FORMAT is used to create user-defined Formats and Informats - Use an FORMAT or ATTRIB statement to permanently associate a variable and a Format

FORMAT FESTIVAL proc format; value $ganpaf '229'='Albany' '706','762'='Athens' '404','470','678','770'='Atlanta’ '478'='Macon' '912'='Savannah'; run; proc print data=ex2; format npa $ganpaf.; run;

FORMAT FESTIVAL Obs npa nxx line revenue 1 Atlanta 423 AAAA Albany 543 XXXX Savannah 333 BBBB Savannah 767 CCCC Atlanta 221 DDDD Macon 332 EEEE Atlanta 681 FFFF Athens 728 GGGG Albany 476 HHHH 31.20

FORMAT FESTIVAL Example 6 – Using a FORMAT to classify data. -Use PROC FORMAT to declare a range instead of just one equivalent value. - Apply the FORMAT range to the original variable in a PROC or DATA step.

FORMAT FESTIVAL proc format; value revtype 0 -< 35 = 'LOW' 36 -< 55 = 'AVERAGE' 56 -< 80 = 'HIGH'; run; data ex3; set ex2; revenue1=revenue; run; proc print data=ex3; format revenue revtype.; var npa nxx line revenue1 revenue; Run;

FORMAT FESTIVAL Obs npa nxx line revenue1 revenue AAAA AVERAGE XXXX HIGH BBBB LOW CCCC LOW DDDD AVERAGE EEEE LOW FFFF LOW GGGG AVERAGE HHHH LOW

FORMAT FESTIVAL Exercise 7 - Using a Format as a look-up facility -Define a FORMAT using PROC FORMAT -Use a PUT function to test each observation AND select by the formatted value

FORMAT FESTIVAL Proc format; value $metro '404','470','678','770'='me'; run; data metro; set ex2; if put(npa,$metro.)='me'; proc print data=metro; title 'Metro Atlanta'; run;

FORMAT FESTIVAL Metro Atlanta Obs npa nxx line revenue AAAA DDDD FFFF 21.7

FORMAT FESTIVAL Example 8 – Creating a Format with the CNTLN option - Create a data set that can be used to construct a Format -Define variables – START, LABEL, FMTNAME as a minimum. -Read the data set into PROC FORMAT using the CNTLN option

FORMAT FESTIVAL

libname ds 'J:\Flash_Drive_4_Gig\SESUG 2006\HW07'; libname library 'J:\Flash_Drive_4_Gig\SESUG 2006\HW07'; data ocnlist; length label $ 50; set ds.nm_ocn_list; start=ocn; label=carrier; fmtname='$New_Mexico_OCN'; run; proc format library=library cntlin=ocnlist; run; proc format library=library fmtlib; select $New_Mexico_OCN; run;

FORMAT FESTIVAL

Traffic Lighting Not a recode, but an improvement in the visual effect of making certain values stand out. Example: Obsnpanxxlinerevenue AAAA XXXX BBBB CCCC DDDD EEEE FFFF GGGG HHHH31.20 FORMAT FESTIVAL

proc format; value larg low ='Green' ='Blue' high='Red'; run; proc print data=subscribers; var npa nxx line; var revenue / style={foreground=larg.}; run; FORMAT FESTIVAL

Obsnpanxxlinerevenue AAAA XXXX BBBB CCCC DDDD EEEE FFFF GGGG HHHH The key element is the use of the “style” option on the revenue variable. -This method is supported for PROC PRINT, PROC TABULATE, and PROC REPORT. -“FORGROUND” controls font color. FORMAT FESTIVAL

Obsnpanxxlinerevenue AAAA XXXX BBBB CCCC DDDD EEEE FFFF GGGG HHHH The “background” attribute controls the cell color. -In Version 8.2, the presence of a permanent FORMAT for the traffic lighting variable prevented the traffic lighting effect when using PROC PRINT. This problem was fixed in Version 9.1 FORMAT FESTIVAL

Nested FORMATS PROC FORMAT; value $metro '404'='City' '470','678','770'='Metro' '229','912'='Outstate' other=[$inter.]; value $inter '803'='SC' '423'='TN' '205'='AL' other='Rest of Country'; run; FORMAT FESTIVAL

ObsnpaNPAnxxlinerevenue 1City404423AAAA Outstate229543XXXX Outstate912333BBBB Outstate912767CCCC Metro678221DDDD Rest of Country478332EEEE Metro770681FFFF Rest of Country706728GGGG Outstate229476HHHH AL205768xxxx35.00 Using the $metro FORMAT to print the subscribers dataset produces the following output: FORMAT FESTIVAL

Version 9.2 New Formats $BASE64X – Converts character data to ASCII text using Base 64 encoding. PERCENTN – Produces percentages, using a minus sign for negative values. DATEW. – Enhanced to write dates in the form dd-mmm-yyy.

FORMAT FESTIVAL This is a very brief look at Formats and Informats. They can help you write some very elegant and concise code. Make them a permanent part of your SAS® repertoire. 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.