SAS Formats

The SAS formats are a type of SAS language element that applies a pattern to or executes instructions for a data value to be displayed or written as output. 

Types of SAS formats: numeric, character, date, time, or timestamp. 

The ability to create user-defined formats is also supported. The examples of SAS formats are BINARY, DATE, and WORDS. 

For example, the WORDS22. format, which converts numeric values to their equivalent in words, writes the numeric value 692 as “six hundred ninety-two.”

Example: Here is the basic example of how SAS formats. I have manually assigned value 15SEP2025 to MYDATE variable. By default SAS stores the date value in numeric format. It means SAS has stored the MYDATE variable value 23999 in the numeric format.

We have used different PUT statements to print the variable MYDATE value in the log but with different SAS formats. These formats are default available in the SAS.

/* sas formats basic example */
data sasformats_example;
	mydate = '15SEP2025'd;
		/* print mydate value in different sas formats*/
	 	put mydate date9.;
   		put mydate worddate3.;
   		put mydate worddate9.;
   		put mydate worddate12.;
   		put mydate worddate20.;
run;
sas formats basic example

The formats can be either temporary (e.g., they only exist within the program) or permanent (e.g., they are saved as a file on the server or computer). Formats for a character variable always start with $, while numeric formats can start with any letter.

If you want to learn more about user-defined formats then check out this detailed guide.

>> PROC FORMAT A-Z GUIDE

Common SAS Formats

Here is the list of common SAS formats:

Type

Formats

Details

Character

$w.

Displays character values of length w.

Numeric

w.d

Displays numeric values of length w with d decimal points

Date

DATEw.

Displays SAS date values of length w.

Time

TIMEw.d

Displays time values in the form hh:mm:ss.ss

Character Formats

  • $w.  : It displays character values to a specified width.
  • $QUOTE w.  : It displays character values in double quotation marks to a specified width.
  • $UPCASEw. : It displays character values in uppercase and optionally truncates them to a specified width.

Here is an example of the $UPCASEw format used with the dataset sashelp.class. The UPCASE format will turn all the characters on the “NAME” variable to uppercase and displays it.

/* UPCASE character format example */
data upcase_example;
	set sashelp.class; 
	format name $upcase.;
run;

/* print names */
proc sql; 
 select name from upcase_example;
quit;
UPCASE character format in SAS example

Character Format With Fixed Length:

Let’s try the UPCASE format with the fixed length of 4 characters. It means names can have a max length of four characters and rest will be truncated as follows:

/* UPCASE character format with fixed length */
data upcase_example;
	set sashelp.class; 
	format name $upcase4.;
run;

/* print names */
proc sql; 
 select name from upcase_example;
quit;
SAS character format with fixed length

Numeric Formats

SAS can handle a wide variety of numeric data formats. SAS use two kinds of numeric formats. One for reading specific formats of the numeric data which is called informat and another for displaying the numeric data in specific format called as output format.

The SAS system uses floating-point representation referred to us as W.D, where W is the width and D is the number of digits to the right of the decimal place.

  • BEST w. : It displays as many significant digits as possible in the output field, but if the numbers vary in magnitude, the decimal points do not line up. Integers are printed without a decimal.
  • w. : It displays a maximum “w” number of digits with no decimal point.
  • w.d : It displays a maximum “w” number of digits with “p” decimal points.
  • COMMAw.d : It displays numeric values with a comma that separates every three digits and a period that separates the decimal fraction.
  • DOLLAR w. d : It displays numeric values with a leading dollar sign, a comma that separates every three digits, and a period that separates the decimal fraction.
  • PERCENT w. d : It multiplies values by 100, formats them the same as the BEST w. d format, and adds a percent sign (%) to the end of the formatted value. Negative values are enclosed in parentheses.

To demonstrate how numeric formats work in SAS, we’ll use the sashelp.cars dataset. The DOLLARw.d format can be applied on the numeric variable “INVOICE” to print invoice amount with dollar currency.

/* numeric format: DOLLARw.d example */
data dollar;
	set sashelp.cars; 
	format invoice dollar8.;
	
	proc print; /* print this dataset */
run;
SAS Dollar Currency Format

Let’s discuss one more example from numeric format, PERCENTw.d. In the below example we are creating a new dataset “work.percent” which has variables like gain1, gain2, gain3 with its allocated numeric values.

The PERCENT10.2 format is applied on all the variables to display data values in the PERCENT format.

/* numeric format: PERCENTw.d example */
data percent;
	gain1 = 1.3; 
	gain2 = 0.701; 
	gain3 = -0.51; 
format gain1 gain2 gain3 percent10.2;
proc print;
run;
SAS PERCENT Format

DATE Formats

The DATE w. format writes SAS date values in the form ddmmmyy, ddmmmyyyy, or dd-mmm-yyyy, where:

  • dd is an integer that represents the day of the month.
  • mmm  is the first three letters of the month’s name.
  • yy or yyyy is a two-digit or four-digit integer that represents the year.

Example Table:

Date FormatsResult
DATE9.15AUG2025
DATE11.15-AUG-2025
MMDDYY10.08/15/2025
YYMMDD10.2025-08-15
WORDDATE.August 15, 2025
DDMMYYP10.15.08.2025
DDMMYYS10.15/08/2025
DDMMYY10.15/08/2025
MMDDYYD8.08-15-25
MMDDYYN8.08152025

If you want to try out how SAS date format works then here is the best example. You can change the MYDATE value here and play around it. The below query gives you different ways to format and display dates in SAS.

/* sas date format */
data sasdate;
	mydate = '26JAN2025'd;
		/* print mydate value in different date formats*/
	 	put mydate date9.;
   		put mydate date11.;
   		put mydate mmddyy10.;
   		put mydate yymmdd10.;
   		put mydate worddate.;
   		put mydate ddmmyyp10.;
   		put mydate ddmmyys10.;
   		put mydate ddmmyy10.;
   		put mydate mmddyyd8.;
   		put mydate mmddyyn8.;
run;
SAS Dates In Different Formats

SAS Date Format Example:

Here is one more example that shows how different date formats can be used on the existing dataset to display date values. We’ll sashelp.stocks dataset where we have variable “DATE”. 

We will create three new variables and apply different date formats.

/* create stock dataset with thre new variables */
data stocks;
	newdate1=date;
	newdate2=date;
	newdate3=date;
set sashelp.stocks;
format newdate1 ddmmyyp10. newdate2 worddate. newdate3 yymmdd10.;
run;

/* print date variables */
proc sql;
	select date, newdate1, newdate2, newdate3 
	from stocks;
quit;
SAS Date Format Examples

SAS software can read two-digit or four-digit year values. If SAS encounters a two-digit year, the YEARCUTOFF= option can be used to specify which century within a 100 year span the two-digit year should be attributed to.

For example, YEARCUTOFF=1950 means that two-digit years 50 through 99 correspond to 1950 through 1999, while two-digit years 00 through 49 correspond to 2000 through 2049.

How to know the current YEARCUTOFF value?

To determine the current YEARCUTOFF= setting, run PROC OPTIONS:

/* check current yearcutoff value */
proc options option=yearcutoff;
run;
SAS Date Year Cut Off Option

How to change the current YEARCUTOFF year?

The YEARCUTOFF year can be set using OPTIONS. For me YEARCUTOFF value is 1940 but this is how I can change it to 1950.

/* set YEARCUTOFF value */
OPTIONS YEARCUTOFF=1950;

FAQ – SAS Formats

What are SAS Formats?

SAS Formats are templates or instructions that dictate how data values should be displayed or interpreted in SAS output. They allow users to control the appearance of data values in various SAS procedures and output formats.

How do SAS Formats differ from Informats?

While SAS Formats control the appearance of data values in output, Informats control how raw data values are read and interpreted by SAS. Formats are typically used to make data more readable for presentation, while Informats are used during data input to ensure correct data interpretation.

Can SAS Formats be customized?

Yes, SAS Formats can be customized to meet specific formatting requirements. Users can create their own custom formats or modify existing ones using SAS programming techniques. Custom formats enable users to tailor the appearance of data values according to their preferences or business needs without altering the underlying data.