Creating Custom Formats in SAS – PROC FORMAT

Welcome back to Mindful Data Minds! In this session, we’ll learn how to create our own formats in SAS using PROC FORMAT. We’ll cover three types of formats:

  • Character format
  • Numeric format
  • Picture format

Watch the Full Tutorial

What You Will Learn

  • How to create picture formats for custom numeric displays.
  • How to create character formats to map codes to labels.
  • How to create numeric formats to group values into ranges.
  • How to apply these formats to datasets for cleaner reporting.

Why Use PROC FORMAT?

Formats let us display values in a more meaningful way. For example:

  • Show M as “Male” and F as “Female”.
  • Group salaries into ranges like “Group 1”, “Group 2”, etc.
  • Display numbers with symbols like $ or .
data a;
infile cards dlm=" " dsd;
input id name $ sex $ sal;
format sal euro10.2;
cards;
1 A M 52.56
2 B F 75.65
3 C  500
;
run;

Picture Format

Picture formats are used to display numbers with special symbols or styles.

Example: Euro Salary Format

proc format;
  picture eur
    low-high ="00,000,000,000,009.99" (mult=100 prefix="€");
run;

data b;
   set a;
   format salary eur.;
run;

Result: 52.56€52.56

Character Format

Character formats map specific values to labels.

Example: Gender Format

proc format;
   value $sx
      'M' = 'Male'
      'F' = 'Female'
      other = 'Unknown';
run;

data c;
   set a;
   format sex $sx.;
run;

Result: M → “Male”, F → “Female”, blank → “Unknown”

Numeric Format

Numeric formats group numeric values into ranges.

Example: Salary Groups

proc format;
   value salary
      0 - 20   = 'Group 1'
      21 - 40  = 'Group 2'
      41 - 60  = 'Group 3'
      61 - 80  = 'Group 4'
      81 - 100 = 'Group 5'
      101 - high = 'Group 6';
run;

data d;
   set a;
   format salary salary.;
run;

Result:

  • 52.56 → “Group 3”
  • 75.65 → “Group 4”
  • 98.12 → “Group 5”
  • 500 → “Group 6”

Next Step

Continue learning by exploring the next tutorial in this series. Also subscribe to get notified about new lessons.

Have a Question?

Drop your doubts in the comments below or contact us.

Leave a Reply

Your email address will not be published. Required fields are marked *