Rabidwolff's Alehouse
"Your place for fun and knowledge."
HOME | Quotes | SAS | C# | BEER



Basics
FORMATS
INFORMATS
DATETIME
ATTRIB
LENGTH
FORMAT
INFORMAT
LABEL
JOINS
OPERATORS

Statements
RETAIN
FIRST.
LAST.

Procedures
PROC SORT
PROC COPY
PROC CPORT
IF ELSE
PROC REPORT

Functions
CAT
CATS
CATT
CATX

CDISC
Random Q & A

CDISC
CDISC Info

Coded Tools
XML Output
Examples

SAS Formats and Informats Information

  • Formats are instruction sets that describe how to save and display data values
  • Informats describe out to read in new data into variables (from external source)
  • The format or informat refer to the same instruction set name
  • There are basically three types of formats and informats: numeric, character and date/time
  • If a problem occurs reading a value, messages are displayed in the SAS log (unless suppressed) and null or blank values are used.
  • <$>format/informat<w>.<d>
    • <$> = add to specify character data type
    • format/informat = name of the instruction set to use
    • <w> = width, usually the length of the value
    • ‘.’ always use a period at the end
    • <d> = decimal places for numeric formats

Character format/informats

  • Character variables only save what the format specifies; any data longer than the width will be cut off (truncated)!
  • If you set the format/informat to a width, it is measured in bytes. Regular encoding uses one byte per character so $5. will only allow 5 characters of data, truncating anything longer.
  • Data is saved up to the shortest specified (between length and format width) if different. Example, a length of $5. and a format of $4. are set, then if 'ABCDE' is saved then only 'ABCD' is actualy saved.

Numeric format/informats

  • Numeric length is number of bytes and does not equal one byte per digit. Format/Informat deals with the number of digits, etc allowed.
  • Numeric formats/informats width will include spaces, special characters, dollar signs, commas, decimal, the decimal point, etc in the count (per format/informat used). Example, a format of 'DOLLAR10.2' would not hold a value of '$123,456.78', you would end up with '$123456.70' while it will hold '$23,456.78'.
  • Numeric variables longer than the format/informat may revert to the BESTw.d format and print ‘**’ to display showing the value is longer than the format specifies
  • Numeric values longer will round
  • Numeric values longer may use Exponents
  • Special Note - SAS can read up to 32 decimal places for numeric informats, 12 or more lose precision due to 8 byte floating point limitations per most computers

Most Common Format/Informats Used

  1. $w. - Character width formats/informats are only used when reading data from an external source.
  2. $UPCASEw. - Automatically upper cases all character values (
  3. w.d - Numeric width formats/informats are used to limit digits/decimals of data since length does not serve this purpose like character lengths.
  4. BESTw. - Same as w.d format but better precision except decimal points not forced to line up.
  5. COMMAw.d - Numeric values with commas and decimal points
  6. DOLLARw.d - Numeric values with dollar sign, commas and decimal points
  7. PERCENTw.d - Numeric values as percentages
  8. Zw.d - Numeric values keeping leading zeros
  9. Link to DATETIME FORMAT Info
  10. Link to External More Complete List of Format/Informats
  11. Link to External SAS's v9.2 Formats List

Most Common Format/Informat Examples

  Syntax Example In Value Saved Value Comments
1 $w. $5. 'ABCDE' 'ABCDE' Holds any value up to 5 characters
2 $UPCASEw. $UPCASE5. 'aBcDe' 'ABCDE' Holds any value up to 5 characters and automatically makes all characters upper case
3 w.d 5.3 1.2345 1.235 Holds 4 digits (including whole numbers, decimal place, and decimal digits) and only up to 3 decimal places. Will truncate/round more digits than allowed to hold.
4 BESTw. BEST6. 1235000 1.24E6 As with w.d format, BESTw. will truncate longer values. Only difference may be when using lots of decimal places and better precision.
5 COMMAw.d COMMA11.1 1000000.1 1,000,000.1 Notice that commas, the decimal place, and the decimal value are counted as part of the '11'. If there isn't enough space for commas to be added then they are not added in.
6 DOLLARw.d DOLLAR13.2 1000000.006 $1,000,000.01 If width is enough (commas and $ are counted as part of the width), will automatically add the $ sign and commas were appropriate, otherwise is the same as a w.d format.
7 PERCENTw.d PERCENT8.2 -0.12345 (12.35%) The input value is multiplied by 100, then the BESTw. format is applied, then a '%' sign is added to the end. If the value is negative, then parenthese are added around the value.
8 Zw.d Z10.5 12 0012.00000
Click to Show Examples:

Rabidwolff Industries | Establisted: 10/15/2011 | Version: 4 8/4/2012 | Page Last Generatated: 9/25/2021 3:59:00 PM