Formatting the output of Frequencies

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Formatting the output of Frequencies

Singh, Amrita
Hi,
 
When I run a Frequencies procedure, the percentages displayed in the
output table only have one decimal place. I know I can edit the table,
right click to change cell properties and change the format to 2 decimal
places. However I have 30-40 tables and it is very tedious to do this
for each table. Is there an option or setting whereby this can be done
globally?

Many thanks,
Amrita Singh
 

====================To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Formatting the output of Frequencies

Peck, Jon
I didn't see a reply to this.

One way, available in all SPSS versions, is to create an autoscript that fires on Frequencies pivot tables, finds the Percentage columns, and calls the SetHDecDigits method.

With SPSS Statistics 17 and the Python Plug-In, there is a much easier way.
The new extension command SPSSINC MODIFY TABLES can apply custom styling to specified cells and/or labels in a pivot table.  It does not have a built-in method for setting the number of decimals, but this can be done very easily using its ability to use plug-in code.

Here's an example,
First, generate a frequency table like this:

FREQUENCIES VARIABLES=educ.

Now use SPSSINC MODIFY TABLES (you can generate this syntax from the dialog box).
SPSSINC MODIFY TABLES subtype="Frequencies"
SELECT="Percent" "Valid Percent" "Cumulative Percent" PROCESS = PRECEDING
/STYLES  APPLYTO=DATACELLS
CUSTOMFUNCTION="customstylefunctions.SetTwoDecimalPlaces".

That picks out the frequency table and the column labeled "Percent" and calls the specified custom function.  So, now you have to write the custom function.  (Actually I have added this to the customstylefunctions module that comes with the extension command, but I haven't updated the online package.)  Those custom functions all have a stock signature, so all you have to do is to write the single line of code that applies the styling you want.  In this case, that would be

obj.SetHDecDigitsAt(i, j, 2)

The whole function is
def SetTwoDecimalPlaces(obj, i, j, numrows, numcols, section, more):
    "Set the cell format to two decimals"
    if section != 'datacells':
      return
    obj.SetHDecDigitsAt(i, j, 2)

To use this, you need SPSS Statistics 17, the Python Plug-In, and the extension command from SPSS Developer Central (www.spss.com/devcentral)

HTH,
Jon Peck


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Singh, Amrita
Sent: Monday, September 29, 2008 10:01 AM
To: [hidden email]
Subject: [SPSSX-L] Formatting the output of Frequencies

Hi,

When I run a Frequencies procedure, the percentages displayed in the
output table only have one decimal place. I know I can edit the table,
right click to change cell properties and change the format to 2 decimal
places. However I have 30-40 tables and it is very tedious to do this
for each table. Is there an option or setting whereby this can be done
globally?

Many thanks,
Amrita Singh


=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD