Hiwa
Hiwa

Reputation:

How to custom format a number in SPSS, like putting percentages between parenthesis?

How to custom format a number in SPSS, like putting percentages between parenthesis? Any help is appreciate. Thanks in advance.

Upvotes: 0

Views: 9451

Answers (3)

Albert-Jan
Albert-Jan

Reputation: 196

If you have SPSS v22 or higher, you could use OUTPUT MODIFY to fine-tune output.

This removes the percent signs in the data values of all pivot tables:

get file = "samples\English\Employee data.sav".
crosstabs educ by gender /cells=row.
output modify /select tables /tablecells select=[body]  format="f10.2".

Custom formats (CCA thru CCD) may also be used. Also, the effect of OUTPUT MODIFY may be limited to certain OMS (sub)types. The following parenthesizes negative values, provided that the OMS subtype is equal to ' Report'. OMS subtypes may be found by right-clicking the output item. OMS stands for "Output Management System".

if ( mod($casenum, 2) eq 0 )  salary = - salary.  /*create some negative values.
summarize salary /cells = min mean max.
set cca "(-,,,)".  /* negative values are parenthesized.
output modify /select tables /if subtypes=['Report'] /tablecells select=[body] format="cca".

Upvotes: 0

Hiwa
Hiwa

Reputation: 1

Thanks a lot. I think a slash is missing before the Keyword style: SPSSINC MODIFY TABLES subtype="frequencies" SELECT "Percent" "Valid Percent" "Cumulative Percent" /STYLES CUSTOMFUNCTION='customstylefunctions.SetNumericFormat(format="##.#%")'

Upvotes: 0

JKP
JKP

Reputation: 5417

Ctables give you extensive control over output cell formats. Most other procedures use a combination of a variable's format and the type of output statistic to construct the format. If you use a custom currency format (defined via Edit > Options > Currency) you have a lot of control over the format.

With SPSSINC MODIFY TABLES, you can set a cell format using one of the custom functions included with the command. Here is an example.

FREQUENCIES var
SPSSINC MODIFY TABLES subtype="frequencies"
SELECT "Percent" "Valid Percent" "Cumulative Percent"
STYLES CUSTOMFUNCTION='customstylefunctions.SetNumericFormat(format="##.#%")'

The formats are referenced the way you see them if you double click a table, select a cell, and chose Cell Formats. This command selects column with the listed labels and changes the cell formats.

To run this command, you need to install the Python Essentials from the SPSS Community website. With V19 or later, this command is installed with the Essentials.

HTH, Jon Peck

Upvotes: 1

Related Questions