SPSS Statistics

 View Only
  • 1.  How to separate values entered as one variable in list format to multiple variables?

    Posted Sun October 18, 2020 09:39 PM

    I am working with a dataset that has values entered as one variable in list format separated by commas (i.e: 1, 2, 3, 4, etc). I would like to separate these values into separate cells (i.e instead of having VAR 1 containing a series of numbers, I would like to have VAR 1, VAR 2, VAR 3, and so on, each containing 1 number per cell).






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: How to separate values entered as one variable in list format to multiple variables?

    Posted Mon October 19, 2020 06:07 PM

    You could write a loop to find the parts and save separate variables, but the easiest way would be to use the SPSSINC TRANS extension command, which you can install from the Extensions > Extension Hub menu.

    Then this code would do it. I assumed the variable is named x and there could be up to ten values.

    spssinc trans result=v1 to v10 type = 0

    /formula 're.split(",", x)'.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: How to separate values entered as one variable in list format to multiple variables?

    Posted Mon January 16, 2023 12:42 PM
    Hi - I am also interested in addressing the same issue. But when I search for SSPSinc Trans, I don't see any extensions by that name.

    Also, could you spell out what we would need to change in the above code to suit our dataset? Is "v1 to v10" the names of the new variables, and where does the name of the old variable go?

    Thank you!

    ------------------------------
    Tamar Wilner
    ------------------------------



  • 4.  RE: How to separate values entered as one variable in list format to multiple variables?

    IBM Champion
    Posted Mon January 16, 2023 12:48 PM
    SPSSINC TRANS is an extension command.  Once installed, it appears on the menus as Transform > Programmability Transformation.  If you don't already have it, you can get it via Extensions > Extension Hub.

    In the example, v1 to v10 are the output variables -  you can use any names or list variables explicitly, and x is the input variable.

    --





  • 5.  RE: How to separate values entered as one variable in list format to multiple variables?

    Posted Wed January 18, 2023 08:52 AM
    you could also do something like this.

    dataset close all.
    DATA LIST LIST
    / variable (A15).
    BEGIN DATA.
    "1, 2, 3, 4"
    "2, 3, 2, 4"
    "5, 2, 1, 4"
    "3, 2, 1, 2"
    "6, 2, 1, 9"
    END DATA.
    string v1 to v4 (a3).
    vector temp=v1 to v4.
    loop i=1 to 4.
    compute a=char.index(variable,', ').
    compute temp(i)=char.substr(variable,1,a-1).
    if a>0 variable=char.substr(variable,a+2,100).
    if a=0 temp(i)=substr(variable,1,75).
    end loop.
    execute.

    ------------------------------
    Art Jack
    ------------------------------