Examples (FORMATS command)

Changing Formats for Multiple Variables

FORMATS SALARY (DOLLAR8) /HOURLY (DOLLAR7.2)
        /RAISE BONUS (PCT2).
  • The print and write formats for SALARY are changed to DOLLAR format with eight positions, including the dollar sign and comma when appropriate. The value 11550 is displayed as $11,550. An eight-digit number would require a DOLLAR11 format: eight characters for the digits, two characters for commas, and one character for the dollar sign.
  • The print and write formats for HOURLY are changed to DOLLAR format with seven positions, including the dollar sign, decimal point, and two decimal places. The value 115 is displayed as $115.00. If DOLLAR6.2 had been specified, the value 115 would be displayed as $115.0. The program would truncate the last 0 because a width of 6 is not enough to display the full value.
  • The print and write formats for both RAISE and BONUS are changed to PCT with two positions: one position for the percentage and one position for the percent sign. The value 9 is displayed as 9%. Because the width allows for only two positions, the value 10 is displayed as 10, since the percent sign is truncated.

Changing Default Variable Formats

COMPUTE V3=V1 + V2.
FORMATS V3 (F3.1).
  • COMPUTE creates the new numeric variable V3. By default, V3 is assigned an F8.2 format (or the default format specified on SET).
  • FORMATS changes both the print and write formats for V3 to F3.1.

Working With Custom Currency Formats

SET CCA='-/-.Dfl ..-'.
FORMATS COST (CCA14.2).
  • SET defines a European currency format for the custom currency format type CCA.
  • FORMATS assigns format CCA to variable COST. With the format defined for CCA on SET, the value 37419 is displayed as Dfl 37.419,00. See the SET command for more information on custom currency formats.