SAS Format Overview and Example Program

A SAS format is an instruction that controls how a stored value is written or displayed. Formats can add commas, currency symbols, decimal places, date separators, and descriptive labels without changing the underlying value in the SAS data set.

For example, the numeric value 12500 can be displayed as 12,500 with COMMA6. or as $12,500 with a suitable DOLLARw. format. The stored value remains 12500.

SAS Format Syntax and Components

</>
Copy
<$>format-name<w>.<d>
ComponentMeaning
$Identifies a character format. Its absence normally indicates a numeric format.
format-nameNames the formatting instruction, such as COMMA, DOLLAR, DATE, or MMDDYY.
wSpecifies the total width of the displayed value, including digits, separators, signs, currency symbols, and decimal places.
dSpecifies the number of digits displayed to the right of the decimal point when the selected numeric format supports it.
.Terminates the format name and is required even when no width or decimal value is written explicitly.

Examples include $20., 8.2, COMMA12.2, DOLLAR12.2, and DATE9.. The meaning and valid width range depend on the individual format.

SAS FORMAT Statement Syntax

The FORMAT statement associates formats with variables. A single statement can assign different formats to several variables or one format to a variable list.

</>
Copy
FORMAT variable-list format. <variable-list format. ...>;
</>
Copy
format salary dollar12.2 balance comma14.2 hire_date date9.;

A format assigned in a DATA step becomes an attribute of the corresponding variable in an output SAS data set. A format assigned inside a procedure controls that procedure’s displayed output and does not permanently alter the source data set.

</>
Copy
data employees;
    set employees_raw;
    format salary dollar12.2 hire_date date9.;
run;

proc print data=employees;
    format salary comma12.2;
run;

In this example, DOLLAR12.2 and DATE9. are stored as variable attributes in the EMPLOYEES data set. The PROC PRINT step temporarily displays SALARY with COMMA12.2 instead.

SAS Formats Compared with Informats

SAS attributePurposeCommon statements and functionsExample
InformatConverts raw input into a SAS valueINPUT, INFORMAT, ATTRIB, and INPUT/INPUTN functionsCOMMA10. reads 12,500 as 12500
FormatControls how a stored SAS value is displayed or writtenFORMAT, ATTRIB, PUT, PUTC, and PUTNCOMMA10. displays 12500 as 12,500

Informats act when SAS reads data. Formats act when SAS displays or writes data. Using a format does not convert a character variable to numeric or a numeric variable to character.

Categories of SAS Formats

  1. Character formats display values stored in character variables, such as $CHARw. and $UPCASEw..
  2. Numeric formats display numeric variables with selected widths, separators, currency symbols, percentages, or other numeric notation.
  3. Date, time, and datetime formats display SAS date, time, and datetime values in readable forms.
  4. Specialized numeric and binary formats write values using representations required by particular systems or file structures.
  5. User-defined formats are created with PROC FORMAT to display stored codes or ranges as meaningful labels.

Common Numeric Formats in SAS

FormatStored valueExample display
8.21250.51250.50
COMMA10.21250.51,250.50
DOLLAR12.21250.5$1,250.50
PERCENT8.10.18518.5%
Z5.4200042
BEST12.1250.5A suitable numeric representation within the available width

The width must be large enough for the complete result. If it is too small, SAS may switch to another representation, reduce decimal detail, or display a row of asterisks, depending on the format and value.

SAS Format Example Program

The following program stores the numeric value 2018 in five variables and applies a different format to each variable in PROC PRINT.

Data formatexample;
 retain var1 - var5 2018;
run;
Proc print data=formatexample width=min noobs;
   format  var1 comma. var2 dollar9. var3 roman20. var4 mmddyy10. var5 mmddyyd10.;
run;

SAS FORMAT Statement Program Output

SAS format Overview- example program

The program does not store five different values. Each variable contains the same numeric value, 2018. The formats only change its representation. In particular, MMDDYY10. and MMDDYYD10. interpret 2018 as a SAS date value—the number of days from January 1, 1960—not as the calendar year 2018.

SAS Date, Time, and Datetime Formats

SAS stores dates and times as numbers. A date is the number of days from January 1, 1960, a time is the number of seconds since midnight, and a datetime is the number of seconds from midnight on January 1, 1960. Formats make those internal numbers readable.

FormatTypical displayValue represented
DATE9.17JUL2026SAS date
DDMMYY10.17/07/2026SAS date
MMDDYY10.07/17/2026SAS date
WORDDATE.July 17, 2026SAS date
TIME8.18:45:30SAS time
DATETIME20.17JUL2026:18:45:30SAS datetime
</>
Copy
data appointments;
    appointment_date = '17JUL2026'd;
    appointment_time = '18:45:30't;
    appointment_dt   = '17JUL2026:18:45:30'dt;

    format appointment_date date9.
           appointment_time time8.
           appointment_dt datetime20.;
run;

The suffixes d, t, and dt identify date, time, and datetime constants. A date format must be assigned to a date value, while a datetime format must be assigned to a datetime value. Applying a date format to a datetime value produces an incorrect-looking result because the two values use different units.

Character Formats in SAS

Character formats begin with a dollar sign and operate on character variables. The basic $w. format writes a character value within a selected width. Other character formats can change how text is represented when it is written.

</>
Copy
data customer_names;
    customer_name = 'David Kumar';
    format customer_name $20.;
run;

A character format and a character informat may have similar names, but they perform different operations. The informat reads raw text into a character variable, while the format writes an existing character value.

User-Defined SAS Formats with PROC FORMAT

PROC FORMAT can create labels for numeric codes, character codes, and numeric ranges. The values stored in the data set remain unchanged.

</>
Copy
proc format;
    value statusfmt
        1 = 'Active'
        2 = 'Inactive'
        3 = 'Pending'
        other = 'Unknown';
run;

data accounts;
    input account_id status;
    format status statusfmt.;
datalines;
101 1
102 3
103 2
104 9
;
run;

proc print data=accounts noobs;
run;

The STATUS variable is still numeric. Reports display its values as Active, Inactive, Pending, or Unknown because STATUSFMT. is associated with the variable.

Using SAS Formats with the PUT Function

The PUT function applies a format and returns a character result. It is useful when a formatted representation must be stored in a new character variable rather than displayed only in output.

</>
Copy
data formatted_values;
    amount = 12500.5;
    sale_date = '17JUL2026'd;

    amount_text = put(amount, dollar12.2);
    date_text = put(sale_date, date9.);
run;

Here, AMOUNT and SALE_DATE remain numeric, while AMOUNT_TEXT and DATE_TEXT are character variables containing formatted text. This differs from a FORMAT statement, which changes the displayed representation without creating a converted character value.

Removing or Overriding a SAS Format

A procedure can temporarily override a stored format by assigning another one. To display a variable with its default representation, list the variable in a FORMAT statement without specifying a replacement format.

</>
Copy
proc print data=employees;
    format salary;
run;

A FORMAT statement containing no variables removes all format associations in the current DATA or PROC step:

</>
Copy
format;

Common SAS Format Problems and Corrections

ProblemLikely causeCorrection
A date displays as an integerNo date format is associated with the variableApply a format such as DATE9. or DDMMYY10.
A datetime displays as an unexpected dateA date format was applied to a datetime valueUse a datetime format such as DATETIME20.
A formatted number does not fitThe selected width is too smallIncrease the width to include digits, separators, signs, and decimals
A variable remains numeric after applying a formatFormats do not change variable typeUse the PUT function when a character result is required
A report shows labels instead of stored codesA user-defined format is attachedRemove or override the format when the underlying codes must be displayed
A format is not foundThe custom format catalog is unavailableMake the required format catalog available or recreate the format with PROC FORMAT

SAS Format Editorial and Program Validation Checklist

  • Confirm that every example distinguishes the stored value from its formatted display.
  • Check that character formats are assigned only to character variables and numeric formats only to numeric variables.
  • Verify that date formats are used with SAS dates and datetime formats with SAS datetime values.
  • Ensure each format width accommodates signs, currency symbols, separators, digits, and decimal places.
  • Confirm that examples requiring type conversion use PUT rather than implying that FORMAT changes the variable type.
  • Check whether formats assigned in a DATA step are intended to remain variable attributes in the output data set.
  • Review user-defined formats for missing, unexpected, and out-of-range values.

SAS Format Frequently Asked Questions

What does a format do in SAS?

A format controls how SAS displays or writes an existing value. It can add commas, decimal places, currency symbols, date separators, or labels without changing the stored value.

What is the difference between a SAS format and informat?

An informat converts raw input into a SAS value. A format converts a stored SAS value into a display or written representation. Informats are associated with reading data, while formats are associated with output.

Does the SAS FORMAT statement change stored data?

No. The FORMAT statement changes the value’s representation, not the underlying value or variable type. Use an appropriate conversion function when a new character or numeric value must be created.

Why does a SAS date need a format?

A SAS date is stored as a numeric day count from January 1, 1960. A date format such as DATE9., DDMMYY10., or MMDDYY10. displays that number as a recognizable calendar date.

How can stored numeric codes be displayed as labels in SAS?

Create a user-defined format with PROC FORMAT, and then associate it with the coded variable. The report displays the labels while the original numeric codes remain stored in the data set.