SPSS FORMATS command has two main uses. This tutorial will briefly demonstrate both of them.
- increasing or decreasing the decimal places of standard numeric variables;
- displaying date, time and datetime values (consisting of numbers of seconds) as normal dates and times.
We recommend you follow along with this tutorial by downloading and opening employees.sav.
Setting Decimal Places
One of the main uses of FORMATS is setting decimal places for standard numeric variables by specifying their desired f formats. For example, we don't see any decimal places for monthly_income in data view except for the formula bar when we select a value (see screenshot).
Its current format, F4, does not only hide all decimals in data view but affects some of the output as well. We can see this by running the following syntax: descriptives monthly_income.
SPSS FORMATS Syntax Example 1
We'll now set two decimal places for monthly_income and rerun the exact same DESCRIPTIVES command with the syntax below.
*2. Rerun descriptives.
Note how all decimal places in the output table have increased by 2 by changing the variable's format. Apart from that, the F7.2 format also displays 2 decimal places in data view now (see next screenshot). Keep in mind that the actual values don't change in any way by running FORMATS.
Setting Date, Time and Datetime Formats
When new date variables, time variables and datetime variables are created, they may initially hold huge numbers that don't look like dates and time at all. These huge numbers are their actual values in numbers of seconds. These are only shown as normal dates and times after setting their formats appropriately. The syntax below demonstrates how to do so.
SPSS FORMATS Syntax Example 2
compute birthday_50 = datesum(date_of_birth,50,'years').
*2. Show numbers of seconds as normal date values.
The reason why this is usually necessary is that SPSS date, time and datetime variables are numeric variables. In SPSS, new numeric variables initially have an f format, usually F8.2. Those who really want to know can confirm this by running show format.
Formats can be set for multiple variables at once; after FORMATS, specify one or more variable names followed by their format. If desired, the command may continue with more variable names, again followed by their format. The syntax below gives an example.
SPSS FORMATS Syntax Example 3
formats education_type to experience_years(f2.1) monthly_income(dollar6) birthday_50(datetime20).