Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Controlling decimal places in output

823 views
Skip to first unread message

mcap

unread,
Jul 23, 2007, 4:24:39 PM7/23/07
to
Is there a way to do this in version 15? How?

Marc

Neila

unread,
Jul 24, 2007, 2:34:55 AM7/24/07
to
On Jul 23, 1:24 pm, mcap <mca...@hotmail.com> wrote:
> Is there a way to do this in version 15? How?
>
> Marc

FORMAT!

Bruce Weaver

unread,
Jul 24, 2007, 3:28:22 PM7/24/07
to
mcap wrote:
> Thanks but I am talking about the output. Not variable set up.
>
> M

I think Marc's concern is that FORMAT affects only certain parts of the
output. Here's an example.

format age (f5.2) / bmi (f5.3) .
descrip age bmi.

Descriptive Statistics
|---------------|----|-------|-------|--------|--------------|
| |N |Minimum|Maximum|Mean |Std. Deviation|
|---------------|----|-------|-------|--------|--------------|
|Age (years) |4434|32.00 |70.00 |49.9258 |8.67693 |
|---------------|----|-------|-------|--------|--------------|
|Body Mass Index|4415|15.540 |56.800 |25.84616|4.101821 |
|---------------|----|-------|-------|--------|--------------|
|Valid N |4415| | | | |
|(listwise) | | | | | |
|---------------|----|-------|-------|--------|--------------|


format age (f5.0) / bmi (f5.2) .
descrip age bmi.

Descriptive Statistics
|---------------|----|-------|-------|-------|--------------|
| |N |Minimum|Maximum|Mean |Std. Deviation|
|---------------|----|-------|-------|-------|--------------|
|Age (years) |4434|32 |70 |49.93 |8.677 |
|---------------|----|-------|-------|-------|--------------|
|Body Mass Index|4415|15.54 |56.80 |25.8462|4.10182 |
|---------------|----|-------|-------|-------|--------------|
|Valid N |4415| | | | |
|(listwise) | | | | | |
|---------------|----|-------|-------|-------|--------------|


The number of decimals shown in the MIN and MAX columns match the
formatting for the variables. But not so for the mean and SD columns.
I believe Marc is asking for a way to format ALL of the columns to the
same number of decimal places; or to specify how many decimals for each
column, etc. Is that right Marc?

--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
"When all else fails, RTFM."

mcap

unread,
Jul 24, 2007, 3:05:44 PM7/24/07
to
Thanks but I am talking about the output. Not variable set up.

M

On Jul 24, 2:34 am, Neila <neilane...@msn.com> wrote:

JKPeck

unread,
Jul 25, 2007, 9:10:06 AM7/25/07
to


Formats in pivot tables and charts are derived from the underlying
variables and the type of statistic. (Sometimes, as for a count
statistic, the variable format is irrelevant). So you can generally
control the output format indirectly by altering the variable format,
even temporarily via the TEMPORARY command. In the case of min, max,
and similar statistics, the variable's format applies directly, while
for means you get more decimals.

Of course, you can edit the cell formats after the table is created,
but to do this in bulk, you would need a script, perhaps an autoscript
that iterated through the cells and applied the format you want.

HTH,
Jon Peck

mcap

unread,
Jul 25, 2007, 2:49:57 PM7/25/07
to
> bwea...@lakeheadu.cawww.angelfire.com/wv/bwhomedir

> "When all else fails, RTFM."

Yes....exactly. Why can't you control this? It takes a lot of extra
time to constantly open the pivot tables and change the cells....

Thanks all!!!

Knock-Off Nigel

unread,
Jul 26, 2007, 7:59:00 AM7/26/07
to
On Wed, 25 Jul 2007 11:49:57 -0700, mcap <mca...@hotmail.com> wrote:

>
>Yes....exactly. Why can't you control this? It takes a lot of extra
>time to constantly open the pivot tables and change the cells....
>
>Thanks all!!!

I think this is a question for Mr Peck. Go ask your programmers sir.
'Why can't you control this?'

Bruce Weaver

unread,
Jul 26, 2007, 9:20:13 AM7/26/07
to


As Jon pointed out, this sort of thing can be done via the scripting
language. I suspect it can be done with a Python program too. But I
agree with Nigel & Marc that those types of work-around solutions are
not very attractive (or useful) to the typical mid-level SPSS user. A
purely syntax-based method would be much more accessible to the average
user.

Meanwhile, here's another work-around solution that does involve syntax
only.

1. use OMS to write the output in question to a data file
2. open the file, and use FORMAT to set the number of decimals
3. use SUMMARIZE or REPORT (etc) to produce the desired output

mwa...@gmail.com

unread,
Jul 26, 2007, 12:23:37 PM7/26/07
to
> bwea...@lakeheadu.cawww.angelfire.com/wv/bwhomedir

> "When all else fails, RTFM."

Hello all,

I have a similar (same?) problem. I need to display the results of
ALSCAL, i.e., text output, with an increased number of decimal places.
How can I achieve that?

Many thanks in advance,
Marcel


JKPeck

unread,
Jul 27, 2007, 11:06:57 AM7/27/07
to


There are many ways to control the formatting and even reshape the
SPSS output, including OMS XML, Scripting apis, and manipulation of
the underlying variable formatting. In addition, Custom Tables gives
you direct control over the cell formats where presentation issues are
important (in the Summary Statistics subdialog). So if you are doing
something repetitively, or you always want columns labeled Mean to
have a certain format, you can automate this.

This does take more advanced skills than some other aspects of using
SPSS (except for Custom Tables), but the automatic rules are designed
to remove the need for this as much as possible. Providing more
control at the dialog box level is a challenging user interface design
task, because it is rare that these format specifications can be
independent of the data or the statistics being computed and the ui
should not be burdensome. I think the Custom Tables approach works
pretty well, since it offers both the automatic rules and explicit
control, but often a user doing ad hoc analyses will not want to
bother with the formatting controls, and the Custom Tables UI offers a
near-WYSIWYG canvas interface that is different from the rest of SPSS,
although the ChartBuilder UI in recent releases is built on the same
model.

I would be curious to see some scenarios where you would want some
absolute formats and would use these often enough that doing the work
by using the user interface is too tedious. I'm not arguing that
these don't exist: I'd just like to know what the most important
scenarios are.

SPSS ships a number of autoscripts with the system that the user can
enable or disable with a click in the Optiohs dialog. It might be
easy to add some that could control particular formatting scenarios
and that would not require the user to know anything about scripting
programming. In SPSS 16, we are adding the ability to have a base
autoscript that can be invoked on every object, so it would be easy to
write rules that apply to every table type. In earlier releases, you
would need an autoscript that is table specific, but it could call a
common formatter routine.

Regards,
Jon Peck

mcap

unread,
Jul 27, 2007, 12:59:09 PM7/27/07
to
> Jon Peck- Hide quoted text -
>
> - Show quoted text -


mcap

unread,
Jul 27, 2007, 1:03:04 PM7/27/07
to
> I would be curious to see some scenarios where you would want some
> absolute formats and would use these often enough that doing the work
> by using the user interface is too tedious. I'm not arguing that
> these don't exist: I'd just like to know what the most important
> scenarios are.

Thanks John. I really appreciate your input. You are correct, there
is probably a decent way to do this but I am a medium user and none of
them are readlity apparent to me. It seems I can have an autoscript
run everytime I produce a particular table in logistic regression (I
always want them to be two decimals - at least for now and I have a
lot of output to open and pivot). When I tried to insert set decimals
autoscript to be triggered by coefficients table however, I kept
getting errors. This is a basic request and I think should be
available. However, any help you can offer for scripting would be
appreciated.
This what I tried to use. But any script that either handles it for
all output or does it by default would be welcome.


Sub SetDecimalDigits(objPivot As PivotTable, intDigits As Integer)
Dim lngRow As Long, lngCol As Long
Dim objDataCells As ISpssDataCells

Set objDataCells = objPivot.DataCellArray

With objDataCells
For lngRow = 0 To .NumRows - 1
For lngCol = 0 To .NumColumns - 1
If Not IsNull (.ValueAt (lngRow, lngCol)) Then
.HDecDigitsAt (lngRow, lngCol) = intDigits
End If
Next
Next
End With

objPivot.Autofit

JKPeck

unread,
Jul 27, 2007, 4:16:57 PM7/27/07
to

I don't have time to dig into this much right now, but is your table
activated? What errors do you get?

autoscripts are hard to debug, so I suggest starting with a script
that gets the currently selected pivot table and walking through it in
the debugger. Then make it into an autoscript.

HTH.
Jon Peck

mcap

unread,
Jul 29, 2007, 12:46:14 PM7/29/07
to
> autoscripts are hard to debug, so I suggest starting with a script
> that gets the currently selected pivot table and walking through it in
> the debugger. Then make it into an autoscript.

Thanks John!! With a little searching and tinkering, I came up with
this one:

Sub LogisticRegression_Table_VariablesintheEquation_Create(objTable As
Object, objOutputDoc As Object, lngIndex As Long)
'Autoscript
'Trigger Event: VariablesintheEquation Table Creation after running
Logistic Regression procedure.

With objTable
.SelectTable
.NumericFormat("#.#", 2)
.ClearSelection
End With
End Sub

Works perfectly. I will just have to change it or delete it if I ever
want to change decimal places again. It's going to make my life a lot
easier. I still think however, that despite the complexities of
variable formatting that you correclty point out, that it should be a
bit easier. I haven't looked at what it takes in Stata but I would
imagine it would be easier. Perhaps I am wrong though.

Thanks again to everyone.

Marc

0 new messages