SPSS Statistics

SPSS Statistics

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

 View Only
Expand all | Collapse all

label variables automatically

  • 1.  label variables automatically

    Posted Thu February 24, 2022 05:57 AM
    Dear all,

    I have a question: I have a large file with more than 100 variables, they are all not labeled 

    I have another file with 2 columns: varNam and Label, the variable names in this file are identical with these in the large file

    how can I label the variables automatically without typing more than 100 times:

    variable labels var1 'total amount ...'  ....

    thanks for your suggestions in advance! 

    best regards

    ------------------------------
    xq OW
    ------------------------------

    #SPSSStatistics


  • 2.  RE: label variables automatically

    Posted Thu February 24, 2022 07:46 AM
    Look up the APPLY DICTIONARY command. It takes such information from one file and applies it to another.

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



  • 3.  RE: label variables automatically

    Posted Thu February 24, 2022 07:59 AM
    Hello rick,

    no,  the second file looks like this:


    var1 var2 ... are not labeled too, I want to automatically run with the big file: 

    variable  Label var1 "this is a test" 

    ... 

    How can I from the 2. file get the information of the value of Labels in the second file and use these for the large file?

    regards,

    ------------------------------
    xq OW
    ------------------------------



  • 4.  RE: label variables automatically

    Posted Thu February 24, 2022 08:20 AM
    OK. If I understand correctly this time, try using the MATCH FILES command, with file 2 as a /TABLE file /KEY=var1.

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



  • 5.  RE: label variables automatically

    Posted Thu February 24, 2022 08:34 AM
    Now that I think more about it...

    1. Make sure Var1 exists in both files.
    2. Both files have to be sorted by var1.
    3. Run this command: MATCH FILES /FILE=file1 /FILE=file2 /BY var1.

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



  • 6.  RE: label variables automatically

    Posted Thu February 24, 2022 08:33 AM
    but my large file looks like this :.( 


    I tried these lines but it doesn't work 

    get file = "C:/Users/xoezen/temp/firstfile.sav" .
    begin program python3.
    import spss, spssdata
    N=spss.GetVariableCount()
    formula ={}
    curs = spssdata.Spssdata()
    for case in curs:
    formula[case.varNam] = case.Labels
    curs.CClose()
    command1 = "get file = mylarge file. "
    for n,c in formula.items():
    command = "VARIABLE LABELS " + n + "'" + "'" + str(c) + ".\n"
    spss.Submit(command)
    end program.


    ------------------------------
    xq OW
    ------------------------------



  • 7.  RE: label variables automatically

    Posted Thu February 24, 2022 08:38 AM
    I don't understand the need for Python here. Could you please send me your data files so I can see them? Maybe then I can understand what your first file contains and what you're trying to do. Thanks.

    email: marcantr@us.ibm.com

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



  • 8.  RE: label variables automatically

    Posted Thu February 24, 2022 08:54 AM
    Take a look at the STATS VALLBLS FROMDATA extension command.  It takes variable values from one variable and creates corresponding value labels for another.  It can be installed via Extensions > Extension Hub.

    From the syntax help...

    STATS VALLBLS FROMDATA
    VARIABLES = variables or VARPATTERN = "regular expression"
    LBLVARS = string variables or LBLPATTERN = "regular expression"

    /OPTIONS
    VARSPERPASS = integer

    /OUTPUT
    SYNTAX = "file"
    EXECUTE=YES** or NO

    /HELP

    * Required
    ** Default


    --





  • 9.  RE: label variables automatically

    Posted Thu February 24, 2022 09:23 AM
    The extension command creates value labels.  If what you want is variable labels, it isn't the right approach.

    --





  • 10.  RE: label variables automatically

    Posted Thu February 24, 2022 09:35 AM
    Jon;

    I sent him a syntax solution which appears to do the trick, at least in my tests of it. He indeed needed VARIABLE LABELS and a list of strings defining those.

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



  • 11.  RE: label variables automatically

    Posted Thu February 24, 2022 03:13 PM
    Hello Rick,

    many thanks for your help! your syntax works fine! a smart solution :-) 

    regards

    ------------------------------
    xq OW
    ------------------------------



  • 12.  RE: label variables automatically

    Posted Thu February 24, 2022 03:14 PM
    As long as it works, I'm happy. You're welcome!

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