SPSS Statistics

 View Only
  • 1.  How Specify variable label be used in ggraph not variable name

    Posted Fri June 24, 2022 10:00 AM
    Is there a way in syntax to specify that the variable label not the variable name be used for graph titles or axis labels

    failing that is there a way to output the variable label prior to calling the ggraph?  If I use Display /variables var1  I get the variable name not the label

    ------------------------------
    Michael
    ------------------------------

    #SPSSStatistics


  • 2.  RE: How Specify variable label be used in ggraph not variable name

    Posted Fri June 24, 2022 10:26 AM
    There is the DISPLAY LABELS command to see labels.

    I don't know of a way to do that other than to manually edit the fields:

    DATA LIST FREE /x.
    BEGIN DATA.
    1 2 3 4 5 6 7 8 9 10
    END DATA.
    VARIABLE LABELS x "My Variable Label".
    DISPLAY LABELS.

    * I see labels by default...

    GGRAPH
     /GRAPHDATASET NAME="graphdataset" VARIABLES=x COUNT()[name="COUNT"] MISSING=LISTWISE
     REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE.
     BEGIN GPL
     GUIDE: axis(dim(1), label("My Variable Label"))
     GUIDE: axis(dim(2), label("Count"))
     GUIDE: text.title(label("Simple Bar Count of My Variable Label"))
     SCALE: linear(dim(2), include(0))
     ELEMENT: interval(position(x*COUNT), shape.interior(shape.square))
    END GPL.
    ​

    ** You can change GUIDE for axis and title manually, of course...

    GGRAPH
     /GRAPHDATASET NAME="graphdataset" VARIABLES=x MISSING=LISTWISE REPORTMISSING=NO
     /GRAPHSPEC SOURCE=INLINE.
    BEGIN GPL
     GUIDE: axis(dim(1), label("x")) 
     GUIDE: axis(dim(2), label("Frequency"))
     GUIDE: text.title(label("Bar of x"))
     ELEMENT: interval(position(summary.count(bin.rect(x))), shape.interior(shape.square))
    END GPL.​


    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: How Specify variable label be used in ggraph not variable name

    Posted Fri June 24, 2022 10:45 AM
    It seems I had an extra axis 
    GUIDE: axis(dim(3), label("This appeared under the chart"))

    Thanks for pointer about display labels but is there a way to just get the label value not the

    Display labels /Variables MyVar1.

    Gets me a table with the variable, position, label and whether its in the working file. I was hoping for just the label value to use it like a sub heading in the output

    ------------------------------
    Michael
    ------------------------------



  • 4.  RE: How Specify variable label be used in ggraph not variable name

    IBM Champion
    Posted Fri June 24, 2022 12:01 PM
    It's not clear to me what you want.  The CODEBOOK procedure can produce a table with just the variable label using the variable name as its title,
    CODEBOOK  salary [s] salbegin [s]
      /VARINFO LABEL
      /STATISTICS NONE.

    The SPSSINC MODIFY OUTPUT could be used with a very small custom function to change table titles to a specified variable's label, or the TEXT extension command could be used to create a formatted text item using a macro that get the text of a variable label.

    If you can clarify what you want, I can show how to do this.

    --





  • 5.  RE: How Specify variable label be used in ggraph not variable name

    Posted Fri June 24, 2022 12:24 PM
    The easiest way to explain it is the value from the Label column in the variable view as a string without any table or structures.
    in pseudo code if Var1 is the variable then Var1.label.AsString() . Your idea of a macro seems matches that but I'm not sure how the macro can get just the variable name 


    ------------------------------
    Michael
    ------------------------------



  • 6.  RE: How Specify variable label be used in ggraph not variable name

    IBM Champion
    Posted Fri June 24, 2022 01:14 PM
    You could do it like this.  The first program sets things up; then you can just
    use the second program to create a macro named !label.
    I illustrated the usage with the TEXT extension command.

    BUT, you can't use macros within GPL text.  You would need to put the GGRAPH command into the program in order to do that.  If that is what you need, I can show you that.

    begin program python3.
    import spss, spssaux
    vardict = spssaux.VariableDict()

    def setlabel(varname):
        spss.SetMacroValue('!label', vardict[varname].VariableLabel)
    end program.

    begin program python3.
    setlabel("salary")
    end program.

    text !label.

    --