1 / 37

Tap Into the Power of Formats

Tap Into the Power of Formats. Introduction Pre-defined formats Custom, User-defined formats More FORMAT Applications Grouping/Recoding Data Table lookups The CTNLIN statement Creating new variables MULTILABEL formats. Tap Into the Power of Formats. Permanent formats Conclusions.

jonny
Download Presentation

Tap Into the Power of Formats

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tap Into the Power of Formats • Introduction • Pre-defined formats • Custom, User-defined formats • More FORMAT Applications • Grouping/Recoding Data • Table lookups • The CTNLIN statement • Creating new variables • MULTILABEL formats

  2. Tap Into the Power of Formats • Permanent formats • Conclusions

  3. Introduction/Review • Formats are instructions that tell SAS how to display variables in output. • These instructions change the look of the variables by mapping one value into another • Example: • SAS date of 17318 will look like June 1, 2007 after a format is applied

  4. Pre-Defined Formats • SAS provides pre-defined formats • SAS has already done the programming – you just apply them to your variables • Examples: • A currency format of: DOLLAR7.2will change: 1346678.32into: $1,346,678.32 • A date/time format of: DATE9. will change: 17457into: 18OCT2007

  5. Pre-Defined Formats • Can be used • when reading in data (an informat – permanent) • during a data step (a format - permanent) • during a procedure (a format - temporary) • Formats accept character or numeric input and always produce character output • Informats always expects character input and can produce character or numeric output

  6. Assigning Informats • Example • DATA MYDIR.NEWFILE; INFILE C011960.PEDS.FCLAIMS.DATA.MAY2203.G0001V00; INPUT @1 HRN $9. @11 CAREDATE YYMMDD10. @23 DEPTNUM 5. ; RUN;

  7. Assigning Formats to Variables in a Data Step • Formats can be used for variables already in a SAS data set that are not in the format you desire • Example • DATA MYDIR.EMPLOYEES;SET OLD; FORMAT BIRTHDATE DATE9.; RUN;

  8. Assigning Formats to Variables in a PROC • Formats can be used to change the look temporarily for a listing or report • Example • PROCPRINT DATA=MYDIR.EMPLOYEES; TITLE 'ACME WIDGET EMPLOYEE BIRTHDAY LIST'; VAR DOB; FORMAT Birthdate worddate18.; RUN;

  9. Custom Formats • Used when pre-defined formats don’t fit your needs • Can be permanent or temporary • Used to: • Convert character strings into numbers • Convert numeric strings into character values • Convert character strings into other character strings

  10. PROC FORMAT • PROC FORMAT Syntax: • PROCFORMAT <option(s)>; VALUE <$>name value_specifications; INVALUE <$>name invalue_specifications; EXCLUDE entry(s); PICTURE name picture_specifications; SELECT entry(s); RUN;

  11. Format Types • Format Types • Character format designated with a “$” before format name, Numeric does not need “$” • Incoming values encased with quotes for character formats, incoming values do not need quotes for numeric data

  12. FORMAT Requirements • Format names limited to 8 characters for SASv8 and earlier and 32 characters for SAS9 and later • Character formats must start with a “$” • FORMAT name cannot begin or end with a number • FORMAT names cannot be identical to pre-defined formats • All mapped values in the VALUE statement must be of the form: • Existing_value = Format_value

  13. Group/Recode Data • Formats can be used to define groups of data for meaningful, project-specific reporting • Replaces IF/THEN/ELSE statements in a DATA step • FORMAT more efficient • Easier to update/maintain

  14. Group/Recode Data • Example • PROC FORMAT ; VALUE PERCEPTION 1 , 2 , . = 'Not at all Serious/Not Very Serious' 3 , 4 , 5 = 'Somewhat Serious/Very Serious' ; VALUE $ REGION 'Franklin','ED','Skyline','Midtown‘ = 'Central ' 'Lakewood','Arapahoe' = 'West ' 'East','Long Term Care','PARC' = 'East ' 'Westminster','Wheatridge','Boulder‘= 'North ' 'Southwest','Smoky Hill','Englewood'= 'South ' other = 'Out Of Area' ; RUN; PROC FREQ DATA=NEWDATA; FORMAT LOC $region. RISK4 perception.; TABLES LOC RISK4; RUN;

  15. Group/Recode Data • Output

  16. Table Lookups • Linking data in one file to related data in another file • MERGE often used • Sort data • Merge datasets together • PROC FORMAT alternative • Less coding • Less CPU • Easier to update with new or different values

  17. Table Lookups • The VALUE statement in PROC FORMAT • PROCFORMAT; VALUE LOCDESC 2 = 'Franklin' 3 = 'Lakewood' 4 = 'ED' 6 = 'East' 7 = 'Westminster' 8 = 'Arapahoe' 9 = 'Southwest' 10 = 'Wheatridge' 77 = 'PARC' ; RUN; PROCFREQ DATA=BYLOCATION; FORMAT LOCATION $LOCDESC.; TABLES LOCATION; RUN;

  18. Table Lookups • The CTNLIN Statement • Used for when you have substantially longer lists of lookups (e.g., ICD-9 descriptions linked to the ICD-9 codes, N=8,000) • Lookup dataset containing ICD-9 and description • Study dataset containing all study data

  19. Table Lookups • The CTNLIN Statement • DATA CONTROL (KEEP=FMTNAME START LABEL); SET MYDIR.DX_CD (KEEP=DX DX_DESC); RETAIN FMTNAME '$DIAGDESC'; RENAME DX=START DX_DESC=LABEL; RUN; PROCSORT DATA=CONTROL NODUPKEY; BY START; RUN; PROCFORMAT CNTLIN=CONTROL; RUN; PROCPRINT DATA=VISITS (OBS=10); VAR DX ; FORMAT DX $DIAGDESC.; TITLE1 'TABLE LOOKUPS USING THE CNTLIN OPTION'; RUN;

  20. Table Lookups • Output using CTNLIN Statement

  21. Creating New Variables • Alternative for transforming data • Can be created from both pre-defined formats or custom, user-defined formats

  22. Creating New Variables • Example • Converting numeric dates into SAS dates using the PUT and INPUT functions • DATA NEWSTUDY;SET MAINFRAME; FORMAT NEWDATE DATE9.; NEWDATE = INPUT( PUT ( OLDDATE,8. ), YYMMDD8.); RUN; PROCPRINT DATA=NEWSTUDY; VAR OLDDATE NEWDATE; RUN;

  23. Creating New Variables • Output

  24. Specifying Ranges of Values • Single values • 6 = “East” • List of values separated by commas • ‘One’,’Two’,’Three’ = “Group 1” • 221, 335, 589 = “Numeric Group” • Inclusive ranges • Numeric or character • 1 – 18 = “Pediatrics”

  25. Specifying Ranges of Values • Exclusive ranges • Numeric or character • 1 -- < 19 = “Pediatrics” • 65 < -- 100 = “Medicare” • Extreme values • Does not format missing values for numeric formats. Missing values included for character formats • Low --< 65 = “Non-Medicare” • 65 – high = “Medicare” • Not specified or out of range • Includes missing values unless accounted for already in the VALUE statement

  26. Multilabel formats • Used when you want to assign a single value to more than one range of values or overlapping range values • Counts single observations in more than one place • In SASv8 and later • Only MEAN, SUMMARY and TABULATE procedures can utilize Multilabel formats

  27. MULTILABEL Formats • Example • We want to group patients in the following age groups • Pediatrics • Adult • Medicare • 0 – 12 • 13 – 18 • 19 – 64 • 65 and higher

  28. MULTILABEL Formats • Example code • PROCFORMAT; VALUE MLTI_FMT (MULTILABEL) 0 - 18 = 'PEDIATRICS' 18 <- <65 = 'ADULT' 65 - HIGH = 'MEDICARE' 0 - 12 = '0 - 12' 13 - 18 = '13 - 18' 19 -< 65 = '19 - 64' 65 - HIGH = '65 & OLDER' ; QUIT;RUN; PROCMEANS DATA=NPDW.JAN98 MEAN MEDIAN; TITLE 'UTILIZING MULTIFORMATS'; FORMAT SVC_AGE MLTI_FMT.; CLASS SVC_AGE/MLF; VAR SVC_AGE; RUN;

  29. MULTILABEL Formats • Output

  30. MULTILABEL Formats • Alternative Code for other sorting • PROCFORMAT; VALUE MLTI_FMT (MULTILABEL NOTSORTED) 0 - 12 = '0 - 12' 13 - 18 = '13 - 18' 19 -< 65 = '19 - 64' 65 - HIGH = '65 & OLDER' 0 - 18 = 'PEDIATRICS' 18 <- <65 = 'ADULT' 65 - HIGH = 'MEDICARE' ; RUN; PROCMEANS DATA=NPDW.JAN98 MEAN MEDIAN; TITLE 'UTILIZING MULTIFORMATS - NOTSORTED'; FORMAT SVC_AGE MLTI_FMT.; CLASS SVC_AGE/MLF PRELOADFMT ORDER=DATA; VAR SVC_AGE; RUN;

  31. MULTILABEL Formats • Output

  32. Saving Formats • Unless otherwise indicated, formats created in your program will be temporary and stored in the temporary Formats Catalog. • Temporary formats deleted when SAS is shut down • Permanent Formats Catalogs may be designated for permanent storage of formats • Maintaining and revising code done only once • Accessible without copying from another program • Accessible to multiple people when saved to a server

  33. Saving Formats • Establish library first • Use LIBNAME statement or New Library window • Default for SAS is to search only the library of predefined SAS formats and in the temporary Formats Catalog in the WORK library • FMTSEARCH option will give SAS explicit search instructions

  34. Saving Formats • Example • LIBNAME DSUG 'G:\ANALYST SAS CODE'; PROCFORMAT LIBRARY=DSUG; VALUE LOCDESC 2 = 'Franklin' 3 = 'Lakewood' 4 = 'ED' 6 = 'East' 7 = 'Westminster' 8 = 'Arapahoe' 9 = 'Southwest' 10 = 'Wheatridge' 77 = 'PARC' ; RUN; OPTIONS FMTSEARCH = (DSUG) NOFMTERR; PROCFREQ DATA=DSUG.LOCATIONS; FORMAT LOCATION $LOCDESC.; TABLES LOCATION; RUN;

  35. Conclusion • FORMATS may be underutilized • FORMATS are powerful • FORMATS are easy to learn • FORMATS are straightforward to use

  36. Questions?

More Related