SPSS Statistics

 View Only
  • 1.  OUTPUT MODIFY - Formatting of neighboring columns

    Posted Fri May 05, 2023 10:02 AM

    Hello,
    I'm dealing with the OUTPUT MODIFY command for the first time (using SPSS 24) and I'm still at the beginning.

    I have already been able to solve some of my problems myself. But now I am faced with a requirement of which I do not know whether this can be implemented at all. Maybe someone in this community can help me.

    I have a frequency table with two data columns: Once the number of cases (n) and to the right the column with the corresponding percentages (%). 
    All n-columns with a total number of cases < 50 are marked in red. In this case, however, the corresponding %-column should also be marked red. And I wonder if this is somehow possible.
    So is it possible to format columns based on a value in the neighboring column with OUTPUT MODIFY?

    Any advice would be appreciated.
    Lisa



    ------------------------------
    ------
    ------------------------------


  • 2.  RE: OUTPUT MODIFY - Formatting of neighboring columns

    IBM Champion
    Posted Fri May 05, 2023 12:16 PM
    OUTPUT MODIFY can't do that, but the SPSSINC MODIFY TABLES extension command can.
    You can install that via Extensions > Extension Hub if you don't already have it.  (It would appear on the menus as Utilities > Modify Table Appearance.)

    Using it for this requires a small custom function.  Here is the code.

    begin program python3.
    def colorit(obj, i, j, numrows, numcols, section, more, custom):
        obj.SetBackgroundColorAt(i, j, 255)
    end program.  

    SPSSINC MODIFY TABLES subtype="'Frequencies'"
    SELECT=0 1
    DIMENSION= COLUMNS LEVEL = -1
    PROCESS = ALL
    /STYLES  APPLYTO="x < 50"
    CUSTOMFUNCTION="__main__.colorit".

    Run the begin program block just once.  The MODIFY TABLES command will color the cells in all the tables of type Frequencies in the Viewer, so you can run it after all the tables are generated, or change ALL to PRECEDING and run it right after the Frequencies command.

    This sets the background color to bright red (255), but you can choose a smaller number if that is too bright.

    If you want to color the text instead of the background, change SetBackGroundColorAt
    in the begin program block to SetTextColorAt and rerun the begin/end block of code.

    --





  • 3.  RE: OUTPUT MODIFY - Formatting of neighboring columns

    Posted Mon May 08, 2023 06:44 AM

    Hey Jon,

    first of all thanks for your quick and detailed reply and the reference to MODIFY TABLES.

    I installed the extension and tested your code. And it works in some way, but I think unfortunately it doesn't do exactly what I want.  I already tried to modify it somehow but failed miserably. :D So maybe you could help me again....

    Let me describe my problem a little more precisely for this.

    Let's assume I have the following SPSS table:

       


    I would now like to check the "Total number of valid cases (frequency)" (here = 50 cases).

    If the number is >= 50, then everything is ok and no coloring should be done - as in this example.
    But if the number is < 50, then the "Frequency column" should be completely colored AND the "Percent column" should be completely colored.
    The background is that I have to make recognizable all data in my tables which are based on a small number of cases . 

    To summarize again, this means that I only check one value in a cell and then based on that cell I want to color the column itself and the neighboring column. 
    Is this somehow possible?

    Kind regards
    Lisa



    ------------------------------
    ------
    ------------------------------



  • 4.  RE: OUTPUT MODIFY - Formatting of neighboring columns

    IBM Champion
    Posted Mon May 08, 2023 09:28 AM
    This will do it.

    begin program python3.
    def colorit(obj, i, j, numrows, numcols, section, more, custom):
        for col in range(numcols):
            obj.SetBackgroundColorAt(i, col, 255)
    end program.  

    SPSSINC MODIFY TABLES subtype="'Frequencies'"
    SELECT=0
    DIMENSION= COLUMNS LEVEL = -1
    PROCESS = ALL
    /STYLES  APPLYTO="x < 50"
    CUSTOMFUNCTION="__main__.colorit".