Study guide
6.4 Creating & Applying Custom Formats with PROC FORMAT
SAS Certified Specialist: Base Programming Using SAS 9.4 A00-231
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: SAS Base Programming Exam Overview
1.1 A00-231 Exam Format, Scoring & Test-Day Logistics 1.2 Official Content Areas, Weights & Study Plan
2 Chapter 2: Accessing & Creating SAS Data Structures
2.1 SAS Environment, Syntax Rules, & Data Step Basics 2.2 SAS Data Libraries & the LIBNAME Statement 2.3 Investigating Libraries with PROC CONTENTS & PROC DATASETS 2.4 Importing Delimited & Excel Data with PROC IMPORT 2.5 Raw Data Ingestion with INFILE and INPUT Statements
3 Chapter 3: Managing & Combining SAS Data Sets
3.1 Reading SAS Data Sets with the SET Statement 3.2 Combining Data Sets: Concatenating & Interleaving 3.3 Match-Merging with BY Statements & FIRST./LAST. Processing 3.4 Controlling Data Output & Variable Selection (KEEP, DROP, RENAME, OBS=)
4 Chapter 4: Data Transformation & Conditional Logic
4.1 Creating & Modifying Variables with Assignment Statements 4.2 Modifying Variable Attributes with LENGTH, LABEL, FORMAT & RENAME= 4.3 Conditional Processing: IF-THEN/ELSE Statements & WHERE Subsetting 4.4 Accumulating Totals & Subtotals (RETAIN & Sum Statement) 4.5 Processing Data Iteratively with DO Loops
5 Chapter 5: SAS Functions & Data Type Conversions
5.1 Character Functions for String Manipulation 5.2 Numeric & Mathematical Functions 5.3 Working with SAS Dates, Times, & Intervals 5.4 Reading & Displaying Dates with Informats and Formats 5.5 Explicit & Implicit Data Type Conversions (INPUT & PUT)
6 Chapter 6: Restructuring Data & Program Maintenance
6.1 SAS Array Processing for Multi-Variable Transformations 6.2 Sorting Data Sets with PROC SORT 6.3 Restructuring Data Sets with PROC TRANSPOSE 6.4 Creating & Applying Custom Formats with PROC FORMAT 6.5 Simplifying Programs with Macro Variables (%LET)
7 Chapter 7: Error Handling & Debugging SAS Programs
7.1 SAS Log Analysis & Diagnostic Messages 7.2 Syntax vs. Logic Errors & Phasing 7.3 Debugging Techniques with _ERROR_, _N_, & PUT Statements 7.4 Identifying Logic Errors with the PUTLOG Statement 7.5 Handling Missing Values & Preventing Calculation Propagations
8 Chapter 8: Summary & Detail Data Reporting
8.1 Detail Reporting with PROC PRINT 8.2 Descriptive Statistics with PROC MEANS & PROC SUMMARY 8.3 Frequency & Categorical Analysis with PROC FREQ 8.4 Screening Extreme & Missing Values with PROC UNIVARIATE 8.5 Custom Tabular Reports with PROC REPORT & PROC TABULATE
9 Chapter 9: ODS Output Delivery & Data Export
9.1 Output Delivery System (ODS) Architecture Basics 9.2 Generating PDF, HTML, & RTF Output Destinations 9.3 Exporting Reports to Excel with ODS EXCEL & XLSX 9.4 Generating CSV, PowerPoint & Other ODS Destinations 9.5 Customizing ODS Titles, Footnotes, & Global Options 9.6 Exporting SAS Data Sets with PROC EXPORT & the XLSX Engine
6.4 Creating & Applying Custom Formats with PROC FORMAT
Key Takeaways Explain This Topic AI
PROC FORMAT creates custom value formats (VALUE), informats (INVALUE), and picture formats (PICTURE) to transform data display without altering underlying stored data values.
Character format names must begin with a dollar sign ($), cannot end in a period in the VALUE statement, and must not exceed 32 characters or end in a number.
The FMTLIB option displays a detailed catalog listing of all user-defined formats, their value ranges, and assigned labels in procedure output.
Custom formats can be exported to SAS datasets using CNTLOUT= and recreated from dataset control files using CNTLIN=, enabling portable format management.
In a FORMAT statement, a period (.) must be appended to the format name (e.g., format status $statfmt.;) to distinguish custom formats from dataset variables.
Last updated: August 2026
6.4 Creating & Applying Custom Formats with PROC FORMAT
In SAS programming, a fundamental architectural principle is the separation of stored data values from displayed formatted values . Raw data stored on disk (e.g., numeric codes 1 , 2 , 3 or raw dates 24103 ) should remain compact and un-mutated, while reports and summaries display human-readable text labels (e.g., 'North America' , 'Europe' , 'Asia' or '07AUG2026' ).
The PROC FORMAT procedure enables programmers to build custom user-defined formats, informats, and picture patterns. Formats facilitate continuous-to-categorical binning, data standardization, label mapping, and dynamic reporting without modifying the underlying dataset.
1. Fundamental Syntax & Format Types
PROC FORMAT supports three distinct user-defined structures:
VALUE Statement : Maps stored data values (or value ranges) into formatted text labels for output display.
INVALUE Statement : Defines informats to convert raw input strings into formatted values during data ingestion ( INPUT statement or INPUT() function).
PICTURE Statement : Defines custom templates for printing numeric data using digit masks (e.g., formatting 10-digit integers as phone numbers (###) ###-#### or Social Security Numbers). PROC FORMAT <LIBRARY=libref<.catalog>> <options>;
- VALUE [$]format_name
- range-1 = 'label-1'
- range-2 = 'label-2'
- other = 'default-label';
- RUN;
- 2. Rules for Naming Custom Formats
Custom format names must comply with strict SAS naming rules. The Base exam frequently tests syntax errors arising from invalid format names:
Rule Character Formats Numeric Formats
Prefix / Dollar Sign MUST begin with a dollar sign ( $ ). CANNOT begin with a dollar sign ( $ ).
Maximum Length Up to 32 characters (including $ ). Up to 32 characters.
Ending Semicolon/Period Do NOT include a period in PROC FORMAT . Do NOT include a period in PROC FORMAT .
Ending Character Cannot end in a digit. Cannot end in a digit.
Reserved Names Cannot match built-in SAS format names (e.g., $CHAR , $HEX ). Cannot match built-in SAS format names (e.g., DATE7 , DOLLAR12 ).
Exam Tip : In PROC FORMAT , the format name must NEVER end with a period (e.g., value $genderfmt ). However, when applying the format in a FORMAT statement or PUT() function, a period MUST be appended (e.g., format Gender $genderfmt.; ).
3. Range Syntax & Mapping Operators in VALUE Statements
When binning numeric values or mapping strings, PROC FORMAT offers rich range specifications:
- Range Syntax Meaning / Example Included Values
- Single Values / Lists 1, 2, 3 = 'Low' or 'M', 'F' = 'Valid' Exact matching values
- Continuous Range 18 - 29 = 'Young Adult' Inclusive bounds ( 18 ≤ x ≤ 29 18 \le x \le 29 18 ≤ x ≤ 29 )
Exclusive Bounds ( < ) 18 -< 30 = '18 to 29' ; 30 <- 50 = '31 to 50' 18 -< 30 ( 18 ≤ x < 30 18 \le x < 30 18 ≤ x < 30 ); 30 <- 50 ( 30 < x ≤ 50 30 < x \le 50 30 < x ≤ 50 )
Open-Ended Keywords LOW - 17 = 'Minor' ; 65 - HIGH = 'Senior' LOW includes all negative infinity up to 17. HIGH includes up to maximum value.
OTHER Keyword OTHER = 'Unknown / Invalid' Catches all values not explicitly covered by preceding ranges (including missing values unless handled). /* Comprehensive PROC FORMAT example with numeric ranges and character maps */
- proc format;
- /* Character format mapping */
- value $status_fmt
- 'A' = 'Active'
- 'I' = 'Inactive'
- 'P' = 'Pending'
- other = 'Unassigned';
- /* Numeric range format with exclusive bounds and missing value handling */
- value age_group
- . = 'Missing Age'
- low -< 18 = 'Under 18'
- 18 -< 35 = '18 to 34'
- 35 -< 65 = '35 to 64'
- 65 - high = '65 and Older';
- run;
- 4. Storing & Searching Permanent Format Catalogs ( LIBRARY= , FMTSEARCH= )
By default, formats created in PROC FORMAT are stored in the temporary catalog WORK.FORMATS and vanish when the SAS session ends. To reuse formats across programs, save them to a permanent library catalog.
Creating Permanent Formats libname myfmts 'C:\SAS_Formats';
- proc format library=myfmts.company_formats;
- value $dept_fmt
- 'HR' = 'Human Resources'
- 'IT' = 'Information Technology'
- 'FIN' = 'Finance';
- run;
- Accessing Permanent Formats with OPTION FMTSEARCH=
When SAS encounters a formatted variable in a DATA step or PROC step, it searches format catalogs in a specific sequence controlled by OPTIONS FMTSEARCH= : /* Set search order: first check myfmts.company_formats, then WORK.FORMATS */
options fmtsearch=(myfmts.company_formats work);
- data work.employee_report;
- set work.raw_employees;
- format Dept $dept_fmt. ;
- run;
Exam Tip : WORK.FORMATS is always searched first unless explicitly included elsewhere in the FMTSEARCH= list.
- 5. Catalog Inspection ( FMTLIB ) & Control Datasets ( CNTLIN= / CNTLOUT= )
- Inspecting Formats with FMTLIB
The FMTLIB option prints a summary table of all format definitions contained in a catalog to the SAS procedure output, showing range start/end points, labels, and type. proc format library=work.formats fmtlib;
- run;
- Creating Formats from Datasets ( CNTLIN= ) & Exporting ( CNTLOUT= )
In large enterprise systems, lookup tables exist as database tables or SAS datasets rather than hardcoded code. PROC FORMAT can build formats dynamically from datasets using CNTLIN= or export catalogs using CNTLOUT= .
Required variables in a CNTLIN= dataset:
FMTNAME : Character string containing the format name (must include $ for character formats).
START : The starting value or range key.
END : The ending value or range key (optional if single value).
LABEL : The formatted text string to display.
TYPE : 'C' for character formats, 'N' for numeric formats, 'I' for informats. /* Building a custom format dynamically from a lookup dataset */
- /* Dataset work.lookup: FMTNAME='$codefmt', START='US', LABEL='United States', TYPE='C' */
- proc format cntlin=work.lookup;
- run;
- 6. Common Pitfalls & Exam Watchouts
Period Syntax Misplacement : Writing value $statusfmt. 'A'='Active'; inside PROC FORMAT generates a syntax error. Remove the period! Conversely, writing format Status $statusfmt; in a DATA step fails to apply the format because the trailing period is missing.
Format Name Ending in a Number : Defining a format named agefmt1 causes a compilation error because format names cannot end in a number.
Missing Format Catalog Error : Opening a dataset that references permanent formats without defining FMTSEARCH= or options nofmterror; produces ERROR: Format $DEPT_FMT not found or cannot be loaded.