SPSS Statistics

SPSS Statistics

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


#Analytics
#SPSSStatistics
#Analyticstools
 View Only
  • 1.  Outputting value labels containing newline

    Posted 11/04/22 07:40 PM
    I am generating value labels using Python's 

    var_label = '\n'.join(['list', 'of', 'strings']).


    When listing the variable labeled that way with the syntax command  LIST my_var. , the newlines are printed as intended and neither errors nor warnings are issued. Obviously, Python's print(var_label) will also print the newlines correctly.

    Running FREQUENCIES VARIABLES=my_var. , however, will give me a

    „One or more values of variable my_var contained a non-printing character. Each such character was replaced by a space. The data file itself was not modified." warning and will actually make good on it. 

    Is it possible to create strings (preferably using Python) that actually print newlines in the three cases described, i.e. print, list and frequencies? Or, as a second choice, at least in the frequencies output?




    #SPSSStatistics


  • 2.  RE: Outputting value labels containing newline

    Posted 11/04/22 07:53 PM
    This is  a little tricky. You want the "\n" to be in the label but not as a literal line break.
    An extra slash will do it.  Here's an example.

    begin program python3.
    import spssaux
       
    vardict = spssaux.VariableDict()
    varlabel = "\\n".join(['part1','part2','part3'])
    vardict['jobcat'].VariableLabel = varlabel
    end program.

    --





  • 3.  RE: Outputting value labels containing newline

    Posted 11/06/22 06:13 AM
    This gets the FREQUENCIES table right, thank you so much!