SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Using variable label as title in custom table

    Posted Mon August 22, 2022 02:16 PM

    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


  • 2.  RE: Using variable label as title in custom table

    Posted Mon August 22, 2022 03:30 PM
    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.

    --





  • 3.  RE: Using variable label as title in custom table

    Posted Tue August 23, 2022 07:42 AM
    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
    ------------------------------



  • 4.  RE: Using variable label as title in custom table

    Posted Tue August 23, 2022 12:34 PM
    Edited by System Admin Fri January 20, 2023 04:47 PM
    Sorry, my post lost a word in the syntax.  It should be
    SPSSINC MODIFY OUTPUT tables
    /IF SUBTYPE="customtable"
    PROCESS=PRECEDING
    /CUSTOM FUNCTION='__main__.cleantitle'
    /REPLACE ITEMS.
    The error message you got isn't clear.  I'll fix that, but try the command with that keyword.

    p.s. OMS table subtypes are internal and are not affected by your language settings.
    --





  • 5.  RE: Using variable label as title in custom table

    Posted Wed August 24, 2022 08:39 AM

    Hello John,

    Thanks again for your answer and your patience! You had the 'TABLES' in your initial syntax and I dropped it kind of by accident / stupidity.

    Now it all works and does what I wanted.

    As I generate my tables with a macro, I now can easily define the BY-line of my breakups beforehand and the program drops that too in all the tables, leaving just the variable label.

    Thank you & take care!



    ------------------------------
    Carsten Fuchs
    ------------------------------