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, and OTHER are 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, and Label are 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 FORMAT and the CNTLIN= option for dynamic format creation.

  • Leverage FMTLIB to 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.