Hello John,
Thank you a lot for your response!
Up until now I never ventured into extensions and never had to, but I think I got everything in order, yet something seems amiss.
An Example.
*******************************
BEGIN PROGRAM python3.
def cleantitle(obj, custom):
tbl = obj.GetSpecificType()
title= tbl.GetTitleText()
tbl.SetTitleText(title.replace("Fallzahl", ""))
END PROGRAM.
CTABLES
/FORMAT EMPTY=' ' MISSING=' '
/VLABELS VARIABLES=F1 AG EG DISPLAY=none
/TABLE valid2 [s][uvalidn] + F1 [c][COLPCT.COUNT F40.0] BY AG + EG
/CATEGORIES VARIABLES=F1 AG EG ORDER=A KEY=VALUE EMPTY=INCLUDE
/SLABELS POSITION=row VISIBLE=NO
/TITLES TITLE=')TABLE'.
SPSSINC MODIFY OUTPUT
/IF SUBTYPE="customtable"
PROCESS=PRECEDING
/CUSTOM FUNCTION='__main__.cleantitle'
/REPLACE ITEMS.
*******************************
I want to get rid of the variable label of valid2, which is 'Fallzahl' (German for case count). Running it like that I get the error message: "'NoneType' object is not iterable".
I tried googling that but as I have no experience with python I could not make much if anything of it.
Not sure whether it's relevant here, but the language of my SPSS is German, in the overview of my output window the customtable is called 'Benutzerdefinierte Tabellen'. I tried changing the SUBTYPE accordingly, but to no avail.
Thanks again & and take care!
------------------------------
Carsten Fuchs
------------------------------
Original Message:
Sent: Mon August 22, 2022 03:29 PM
From: Jon Peck
Subject: Using variable label as title in custom table
You can do this with the SPSSINC MODIFY OUTPUT extension command. You can install that via Extensions > Extension Hub if you don't already have it.
This code would just eliminate the "case count " text in the title. Note that I included the blank that presumably follows "case count".
First you run this code to define the custom function. You only need to run it once in a session.
begin program python3.
def cleantitle(obj, custom):
tbl = obj.GetSpecificType()
title= tbl.GetTitleText()
tbl.SetTitleText(title.replace("case count", ""))
end program.
Then for each table you want to modify, run a command like this after the CTABLES command. As written, it just works on the immediately preceding CTABLES command, but you can change it to PROCESS=ALL if you want to have it clean all CTABELS tables in the output. Note that the matching text is case sensitive.
SPSSINC MODIFY OUTPUT TABLES
/IF SUBTYPE="customtable"
PROCESS=PRECEDING
/CUSTOM FUNCTION='__main__.cleantitle'
/REPLACE ITEMS.
If you want something that would actually look up the label for a specified variable and use that as the replacement, this is possible with a bit more code, but, of course, it probably wouldn't work with PROCESS=ALL, since you would have to specify the variable whose label should be used.
--