In crosstab tables, for one instance, I'd like to change the reporting of percents from xx.x% to xx.xx%--two decimal digits not one. Table by table, I can manually open each table, select the cells, change the cell format properties, and close the table. I had imagined that a so-called tablelook could be defined and be called to apply to crosstab tables from that point forward in the syntax execution. However, I read the documentation for tablelooks and edited the default it looks as if a tablelook does not control cell data display formats. Am I right? If I'm wrong, and I hope I am, how do you do it? If I'm not, is there any way to do what I want to do?
Thanks, Gene Maguin ===================== 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 |
TableLooks do not control the cell
formats, but you can automate this change by writing an autoscript or using
the SPSSINC MODIFY TABLES extension command included in the Python Essentials.
You didn't say what tables you want to do this for, but here is an example that changes the % formatting for all FREQUENCIES tables. SPSSINC MODIFY TABLES subtype="Frequencies" SELECT=".*Percent" REGEXP=YES DIMENSION= COLUMNS LEVEL = -1 PROCESS = ALL /STYLES APPLYTO=DATACELLS CUSTOMFUNCTION="customstylefunctions.SetDecimalPlaces(decimals=2)". It looks for any column title ending with "Percent" in tables with OMS subtype of "Frequencies" and sets the decimals to 2. In the case of Frequencies, this will match three of the columns in the table. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: "Maguin, Eugene" <[hidden email]> To: [hidden email], Date: 06/05/2013 02:38 PM Subject: [SPSSX-L] table looks?? Sent by: "SPSSX(r) Discussion" <[hidden email]> In crosstab tables, for one instance, I'd like to change the reporting of percents from xx.x% to xx.xx%--two decimal digits not one. Table by table, I can manually open each table, select the cells, change the cell format properties, and close the table. I had imagined that a so-called tablelook could be defined and be called to apply to crosstab tables from that point forward in the syntax execution. However, I read the documentation for tablelooks and edited the default it looks as if a tablelook does not control cell data display formats. Am I right? If I'm wrong, and I hope I am, how do you do it? If I'm not, is there any way to do what I want to do? Thanks, Gene Maguin ===================== 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 |
In reply to this post by Maguin, Eugene
The number of decimals in the output depends on the (combination of) procedure, statistic and variable formats. The easiest way to exert some (but not a lot) of control over decimal places is modifying the variable formats but that won't help in this case.
Your two basic options are 1) a SaxBasic script (if Python is really not an option, I believe Raynald Levesque has one on his site you could use) 2) a Python script, either generated by the MODIFY TABLES extension (as pointed out by Jon) or a "raw" Python script (which is longer but I personally find it more readable). You could obviously hide that behind a toolbar tool/custom dialogue/whatever The most basic way to set 2 decimal places for cells in crosstabs would be The number of decimals in the output depends on the (combination of) procedure, statistic and variable formats. The easiest way to exert some (but not a lot) of control over decimal places is modifying the variable formats but that won't help in this case. Your two basic options are 1) a SaxBasic script (if Python is really not an option, I believe Raynald Levesque has one on his site you could use) 2) a Python script, either generated by the MODIFY TABLES extension (as pointed out by Jon) or a "raw" Python script (which is longer but I personally find it more readable). You could obviously hide that behind a toolbar tool/custom dialogue/whatever For crosstabs percentages that would be (hope the indentation comes through correctly) data list free/id. begin data 1 2 3 4 5 6 7 8 9 10 end data. do repeat v = v1 to v5. compute v=tru(rv.uni(1,6)). end repeat. crosstabs v1 by v2 to v5 /cells column. begin program. import SpssClient SpssClient.StartClient() oDoc = SpssClient.GetDesignatedOutputDoc() oItems = oDoc.GetOutputItems() for index in range(oItems.Size()): oItem = oItems.GetItemAt(index) if "Crosstabulation" in oItem.GetDescription() and oItem.GetType() == SpssClient.OutputItemType.PIVOT: pTable = oItem.GetSpecificType() dCells=pTable.DataCellArray() for rows in range(dCells.GetNumRows()): for cols in range(dCells.GetNumColumns()): dCells.SetHDecDigitsAt(rows,cols,2) SpssClient.StopClient() end program. |
Free forum by Nabble | Edit this page |