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.
--
Original Message:
Sent: 8/22/2022 5:23:00 AM
From: Carsten Fuchs
Subject: Using variable label as title in custom table
Hello community,
Does anyone have an idea how I can use the label of the variable I'm looking at as the title of a custom table without typing or copying it into /TITLES TITLE=?
- ')TABLE' nearly does the trick, but as I have a case count above all the other numbers my title would always start with 'case count', and with lots of breakups it gets messy fast.
- Something like ')VARLABEL(Q1)' would be great, but I just made that up.
- I'm guessing (hoping) there is a way to get the title via macro and then have something like TITLE=!varname, but could not get that to work yet.
I work with SPSS 27, and doing a search here or on the net* I couldn't find a suggestion besides ')TABLE', which is not what I'm looking for.
*As an aside, lately I get the message: "Product version no longer published - SPSS Statistics 24.0.0 is no longer published." on IBM.com 90 % of the time when I get to the site via a google search using keywords without referring to a SPSS version. That is quite annoying.
Thanks & take care!
Carsten
------------------------------
Carsten Fuchs
------------------------------
#SPSSStatistics