Previous Page | Next Page

Formats

Working with Packed Decimal and Zoned Decimal Data


Definitions

Packed decimal

specifies a method of encoding decimal numbers by using each byte to represent two decimal digits. Packed decimal representation stores decimal data with exact precision. The fractional part of the number is determined by the informat or format because there is no separate mantissa and exponent.

An advantage of using packed decimal data is that exact precision can be maintained. However, computations involving decimal data might become inexact due to the lack of native instructions.

Zoned decimal

specifies a method of encoding decimal numbers in which each digit requires one byte of storage. The last byte contains the number's sign as well as the last digit. Zoned decimal data produces a printable representation.

Nibble

specifies 1/2 of a byte.


Types of Data


Packed Decimal Data

A packed decimal representation stores decimal digits in each "nibble" of a byte. Each byte has two nibbles, and each nibble is indicated by a hexadecimal character. For example, the value 15 is stored in two nibbles, using the hexadecimal characters 1 and 5.

The sign indication is dependent on your operating environment. On IBM mainframes, the sign is indicated by the last nibble. With formats, C indicates a positive value, and D indicates a negative value. With informats, A, C, E, and F indicate positive values, and B and D indicate negative values. Any other nibble is invalid for signed packed decimal data. In all other operating environments, the sign is indicated in its own byte. If the high-order bit is 1, then the number is negative. Otherwise, it is positive.

The following applies to packed decimal data representation:


Zoned Decimal Data

The following applies to zoned decimal data representation:


Packed Julian Dates

The following applies to packed Julian dates:


Platforms Supporting Packed Decimal and Zoned Decimal Data

Some platforms have native instructions to support packed and zoned decimal data, while others must use software to emulate the computations. For example, the IBM mainframe has an Add Pack instruction to add packed decimal data, but the Intel-based platforms have no such instruction and must convert the decimal data into some other format.


Languages Supporting Packed Decimal and Zoned Decimal Data

Several languages support packed decimal and zoned decimal data. The following table shows how COBOL picture clauses correspond to SAS formats and informats.

IBM VS COBOL II clauses Corresponding S370Fxxx formats/informats
PIC S9(X) PACKED-DECIMAL S370FPDw.
PIC 9(X) PACKED-DECIMAL S370FPDUw.
PIC S9(W) DISPLAY S370FZDw.
PIC 9(W) DISPLAY S370FZDUw.
PIC S9(W) DISPLAY SIGN LEADING S370FZDLw.
PIC S9(W) DISPLAY SIGN LEADING SEPARATE S370FZDSw.
PIC S9(W) DISPLAY SIGN TRAILING SEPARATE S370FZDTw.

For the packed decimal representation listed above, X indicates the number of digits represented, and W is the number of bytes. For PIC S9(X) PACKED-DECIMAL, W is ceil((x+1)/2) . For PIC 9(X) PACKED-DECIMAL, W is ceil(x/2) . For example, PIC S9(5) PACKED-DECIMAL represents five digits. If a sign is included, six nibbles are needed. ceil((5+1)/2) has a length of three bytes, and the value of W is 3.

Note that you can substitute COMP-3 for PACKED-DECIMAL.

In IBM assembly language, the P directive indicates packed decimal, and the Z directive indicates zoned decimal. The following shows an excerpt from an assembly language listing, showing the offset, the value, and the DC statement:

offset  value (in hex)      inst label     directive

+000000 00001C                2 PEX1       DC PL3'1' 
+000003 00001D                3 PEX2       DC PL3'-1'
+000006 F0F0C1                4 ZEX1       DC ZL3'1' 
+000009 F0F0D1                5 ZEX2       DC ZL3'1'  

In PL/I, the FIXED DECIMAL attribute is used in conjunction with packed decimal data. You must use the PICTURE specification to represent zoned decimal data. There is no standardized representation of decimal data for the Fortran or the C languages.


Summary of Packed Decimal and Zoned Decimal Formats and Informats

SAS uses a group of formats and informats to handle packed and zoned decimal data. The following table lists the type of data representation for these formats and informats. Note that the formats and informats that begin with S370 refer to IBM mainframe representation.

Format Type of data representation Corresponding informat Comments
PD Packed decimal PD Local signed packed decimal
PK Packed decimal PK Unsigned packed decimal; not specific to your operating environment
ZD Zoned decimal ZD Local zoned decimal
none Zoned decimal ZDB Translates EBCDIC blank (hexadecimal 40) to EBCDIC zero (hexadecimal F0); corresponds to the informat as zoned decimal
none Zoned decimal ZDV Non-IBM zoned decimal representation
S370FPD Packed decimal S370FPD Last nibble C (positive) or D (negative)
S370FPDU Packed decimal S370FPDU Last nibble always F (positive)
S370FZD Zoned decimal S370FZD Last byte contains sign in upper nibble: C (positive) or D (negative)
S370FZDU Zoned decimal S370FZDU Unsigned; sign nibble always F
S370FZDL Zoned decimal S370FZDL Sign nibble in first byte in informat; separate leading sign byte of hexadecimal C0 (positive) or D0 (negative) in format
S370FZDS Zoned decimal S370FZDS Leading sign of - (hexadecimal 60) or + (hexadecimal 4E)
S370FZDT Zoned decimal S370FZDT Trailing sign of - (hexadecimal 60) or + (hexadecimal 4E)
PDJULI Packed decimal PDJULI Julian date in packed representation - IBM computation
PDJULG Packed decimal PDJULG Julian date in packed representation - Gregorian computation
none Packed decimal RMFDUR Input layout is: mmsstttF
none Packed decimal SHRSTAMP Input layout is: yyyydddFhhmmssth, where yyyydddF is the packed Julian date; yyyy is a 0-based year from 1900
none Packed decimal SMFSTAMP Input layout is: xxxxxxxxyyyydddF, where yyyydddF is the packed Julian date; yyyy is a 0-based year from 1900
none Packed decimal PDTIME Input layout is: 0hhmmssF
none Packed decimal RMFSTAMP Input layout is: 0hhmmssFyyyydddF, where yyyydddF is the packed Julian date; yyyy is a 0-based year from 1900

Previous Page | Next Page | Top of Page