Introduction
Welcome to Edition 13 of Making SAS Accessible to Everyone. This edition introduces an essential skill for improving the readability, presentation, and interpretability of SAS output, custom formats.
Custom formats allow you to:
Label raw codes with human-readable text.
Group numeric values into categories.
Apply consistent presentation standards across multiple reports.
Whether you’re working with categorical survey data or producing professional summary tables, PROC FORMAT in SAS is your gateway to customization and clarity.
1. What is a Custom Format?
A custom format lets you map raw data values (e.g., 1, 2, 3) to descriptive labels (e.g., ‘Low’, ‘Medium’, ‘High’).
Unlike traditional formatting, custom formats:
Can be reused across datasets and procedures.
Enhance output interpretation without altering raw data.
Work for both numeric and character values.
2. Creating Custom Formats Using PROC FORMAT
Syntax:
PROC FORMAT;
VALUE format-name
range-or-value-1 = 'label-1'
range-or-value-2 = 'label-2'
...;
RUN;
Example:
PROC FORMAT;
VALUE riskfmt
1 = 'Low'
2 = 'Medium'
3 = 'High';
RUN;
Applying the Format:
PROC PRINT DATA=patients;
FORMAT RiskLevel riskfmt.;
RUN;
Format names for numeric values start with a letter or underscore.
Format names for character values start with a
$.You do not use a period when creating the format, but do use it when applying it.
3. Enhancing Format Logic
Using Ranges:
PROC FORMAT;
VALUE agegrp
0 - 12 = 'Child'
13 - 19 = 'Teenager'
20 - 64 = 'Adult'
65 - HIGH = 'Senior';
RUN;
LOW,HIGH, andOTHERare special keywords.- Useful for bucketizing continuous values like age or income.
4. Creating Character Formats
Example:
PROC FORMAT;
VALUE $genderfmt
'M' = 'Male'
'F' = 'Female'
'U' = 'Unknown';
RUN;
Application:
PROC FREQ DATA=survey;
TABLES Gender;
FORMAT Gender $genderfmt.;
RUN;
5. Creating Formats from a Dataset (CNTLIN=)
You can use an input dataset to create formats dynamically:
Step 1: Create the Control Table
DATA fmtdata;
INPUT FmtName $ Start $ Label $;
DATALINES;
$dept D1 "Finance"
$dept D2 "HR"
$dept D3 "IT"
;
RUN;
Step 2: Build the Format
PROC FORMAT CNTLIN=fmtdata;
RUN;
- Columns
FmtName,Start, andLabelare required. - Format is stored and ready for use in procedures.
6. Listing and Documenting Formats
Use FMTLIB to display existing formats:
PROC FORMAT LIB=work FMTLIB;
SELECT riskfmt agegrp $genderfmt;
RUN;
- Helpful for verifying format definitions and inspecting format libraries.
7. Use Cases and Best Practices
Example: Grouping Ages in a Report
PROC FORMAT;
VALUE ageband
LOW-17 = 'Youth'
18-64 = 'Adult'
65-HIGH = 'Senior';
RUN;
PROC MEANS DATA=census;
CLASS Age;
FORMAT Age ageband.;
RUN;
Tips:
Always use descriptive format names.
Use
OTHER = 'Unknown'to catch unexpected values.Store reusable formats in a permanent library for consistency.
Conclusion
In Edition 13, you learned to:
Create and apply custom numeric and character formats.
Use
PROC FORMATand theCNTLIN=option for dynamic format creation.Leverage
FMTLIBto document and inspect formats.
Custom formats are a cornerstone of professional SAS reporting, allowing you to present data with clarity and consistency.
What’s Next
In Edition 14, we will begin working with on combining Tables.
Format smartly with 3 D Statistical Learning.
Special thanks to Dr. Dany Djeudeu for elevating data presentation through thoughtful formatting in SAS.
We help businesses and researchers solve complex challenges by providing expert guidance in statistics, machine learning, and tailored education.
Our core services include:
– Statistical Consulting:
Comprehensive consulting tailored to your data-driven needs.
– Training and Coaching:
In-depth instruction in statistics, machine learning, and the use of statistical software such as SAS, R, and Python.
– Reproducible Data Analysis Pipelines:
Development of documented, reproducible workflows using SAS macros and customized R and Python code.
– Interactive Data Visualization and Web Applications:
Creation of dynamic visualizations and web apps with R (Shiny, Plotly), Python (Streamlit, Dash by Plotly), and SAS (SAS Viya, SAS Web Report Studio).
– Automated Reporting and Presentation:
Generation of automated reports and presentations using Markdown and Quarto.
– Scientific Data Analysis:
Advanced analytical support for scientific research projects.