sasSAS Formats


Introduction

Informats and formats are used to tell SAS how to read and write the data respectively. Informats are commonly used in a datastep when reading data from an external file. Informats are rarely used in PROCs. Formats are commonly used in both data steps and PROCs.

Remarks

SAS Formats convert either numeric or character values to character values. A format can either be applied using a format or put statement, which changes the way a value is displayed, or using the put function to store the formatted value in a new variable.


There are four categories of formats :

  • Character - instructs SAS to write character data values from character variables.
  • Date and Time - instructs SAS to write data values from variables that represent dates, times, and datetimes.
  • ISO 8601 - instructs SAS to write date, time, and datetime values using the ISO 8601 standard.
  • Numeric - instructs SAS to write numeric data values from numeric variables.

Formats usually take the form <formatname><w>.<d>;, w being the width (including any decimals and the point), d being the number of decimal places.


Common date formats (applied to SAS date values) :

  • date9. e.g. 02AUG2016
  • ddmmyyn8. e.g. 02082016
  • ddmmyy8. e.g. 02/08/16
  • yymmdd10. e.g. 20160802
  • year4. e.g. 2016

Common numeric formats (applied to numbers) :

  • comma11.0 e.g. 1,234,567
  • comma12.2 e.g. 1,234,567.00
  • dollar11.2 e.g. $5,789.12
  • nlmnlgbp11.2 e.g. £2,468.02

Other formats :

  • $hex8., convert string to hex
  • $upcase., convert string to upper-case
  • $quote., enclose a string in quotes

A full list of formats can be found here > https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm