I could not find a way to do this with CTABLES syntax, including PCOMPUTE, but a colleague did provide a Python solution. If you have the Python Essentials installed (which are installed by default on recent versions), copy and paste the following code into a syntax window, and after running CTABLES, run it.
preserve.
set printback none.
begin program python3.
import SpssClient
SpssClient.StartClient()
OutputDoc = SpssClient.GetDesignatedOutputDoc()
OutputItems = OutputDoc.GetOutputItems()
for index in range(OutputItems.Size()):
OutputItem = OutputItems.GetItemAt(index)
if OutputItem.GetType() == SpssClient.OutputItemType.PIVOT:
PivotTable = OutputItem.GetSpecificType()
ColLabels = PivotTable.ColumnLabelArray()
for i in range(0,ColLabels.GetNumRows()):
for j in range(ColLabels.GetNumColumns()):
try:
colText=ColLabels.GetValueAt(i,j)
if colText == "Missing":
MissingColumn=j
if colText == "Valid N":
ValidNColumn=j
if colText == "Total N":
TotalNColumn=j
except:
pass
DataCells = PivotTable.DataCellArray()
for i in range(DataCells.GetNumRows()):
MissingVal=(DataCells.GetValueAt(i,MissingColumn))
ValidN=(DataCells.GetValueAt(i,ValidNColumn))
TotalN=(DataCells.GetValueAt(i,TotalNColumn))
val= str( 100 * float(MissingVal)/float(TotalN) )
DataCells.SetValueAt(i,MissingColumn,val)
DataCells.SetNumericFormatAtWithDecimal(i,MissingColumn,"##.#%",1)
SpssClient.StopClient()
end program.
restore.
Here's what the result looks like with a small example dataset:
