SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Fri December 04, 2020 09:21 AM
      |   view attached
    Hi Friends 
    I'm new in SPSS and struggling to split multiple value from one variable to multiple variables. Is anyone can help me how to do that in syntax or using menu bar. See the attached file pls. 

    Thank you,
    Akter

    ------------------------------
    Akter Hossain
    ------------------------------

    #SPSSStatistics

    Attachment(s)

    sav
    Partial_data.sav   3 KB 1 version


  • 2.  RE: splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Fri December 04, 2020 10:20 AM
    Edited by System Admin Fri January 20, 2023 04:09 PM
    I presume that you want to split Q1A and Q6A on the comma character.  Please be more explicit with your questions.

    You can do this in standard SPSS Statistics syntax with a loop and the substrings functions, but I am going to show you a simpler
    way to do this using the SPSSINC TRANS extension command (example for Q1A).

    spssinc trans result = part1 part2 type=5
    /formula "re.split(',', Q1A)".

    This creates two new string variables, part1 and part2, of length five splitting on the comma character.  The reference to the variable must match the letter case: q1a would  not work.

    You can install SPSSINC TRANS from the Extensions > Extension Hub menu.  Search for trans.

    ------------------------------
    Jon Peck
    ------------------------------



  • 3.  RE: splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Tue June 01, 2021 02:06 PM
    John, I would like to ask you further question, 
    I have implemented the solution provided . It works. Now, I have the following results, that I need some clarifications or guidance 


    Based on what we read , for check all that apply variable, split function will create new variables.  

    Initial Stage

    Source of Income

    Client

    Benefit ; EI ; CERB

    1

    EI ; Support ; Benefit

    2

    Support; CERB; EI

    3

     

    Applied Syntax 
    spssinc trans result = Source1 to Source3      type=25  
    /formula "re.split(',', Source of Income)".


    Source 1

    Source 2

    Source 3

    Client

    Benefit

    EI

    CERB

    1

    EI

    Support

    Benefit

    2

    Support

    CERB

    EI

    3

     

     As you could see from the example above, Source 1 or Source 2 or Source 3 contains income source that is similar for 3 cases. 
    Question, what is the way to evaluate scenario above. Or if there is a way to create variables based on value and name variables as the example below.

     Source Benefit

    Source EI

    Source CERB

    Source Support

    Client

    1

    1

    1

    0

    1

    1

    1

    0

    1

    2

    0

    1

    1

    1

    3


    thank you in advance 
    Kamal


    ------------------------------
    Tolife Tolife
    ------------------------------



  • 4.  RE: splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Tue June 01, 2021 04:00 PM
    This is a little trickier, since a source might not appear in a record.

    Run the begin program block once and then run spssinc trans.  Note that the letter case of the input variable name in TRANS must match the case in the dataset.

    data list fixed/Source(a30).
    begin data
    Benefit;EI;CERB      
    EI;Support;Benefit  
    end data.
    dataset name data.

    begin program python3.
    positions = ["Benefit", "EI", "CERB", "Support"]
    def splitup(source):
        res = []
        args = [item.rstrip() for item in source.split(";")]
        for v in positions:
            if v in args:
                res.append(1)
            else:
                res.append(0)
        return res
    end program.
        

    spssinc trans result=SourceBenefit SourceEI SourceCERB SourceSupport
    /formula "splitup(Source)".


    --





  • 5.  RE: splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Wed June 02, 2021 08:38 AM
    Thank you John. 
    As from what I understood, for
    data list fixed/Source(a30). 
    Benefit;EI;CERB     
    EI;Support;Benefit  
    end data.

    I could apply the available All picklist list for particular variable Source of Income? and not rely on the responses?
    Like this 

    Step 1.


    data list fixed/Source(a30).
    Canada pension; CERB; Don't know; EI or Maternity Leave ;Financial support from family member; I prefer not to answer; Investment(s) ;Job ;Loan; No income to report ;Old age security pension; Other source(s);Other sources; Personal savings; Privately sponsored ;Provincial Disability Support Program (e.g.,ODSP, etc.);Scholarship(s);Self-employment ;Social assistance/welfare; Spouse/parent employment income; Training allowance
    end data.

    Step 2.

    Same for begin program python3.
    positions = ["Benefit", "EI", "CERB", "Support"]             is my All original picklist values ?

    Like this 

    begin program python3.
    positions = ["Canada pension", "CERB", "Don't know", "EI or Maternity Leave ","Financial support from family member", "I prefer not to answer", "Investment(s) ","Job ","Loan", "No income to report ","Old age security pension", "Other source(s)","Other sources", "Personal savings", "Privately sponsored ","Provincial Disability Support Program (e.g.,ODSP, etc.)","Scholarship(s)","Self-employment ","Social assistance/welfare", "Spouse/parent employment income", "Training allowance"]

    def splitup(source):
        res = []
        args = [item.rstrip() for item in source.split(";")]
        for v in positions:
            if v in args:
                res.append(1)
            else:
                res.append(0)
        return res
    end program.


    Step3
    spssinc trans result= SourceCERB SourceDon't know SourceEI or Maternity Leave SourceFinancial support from family member SourceI prefer not to answer SourceInvestment(s) SourceJob SourceLoan SourceNo income to report SourceOld age security pension SourceOther source(s) SourceOther sources SourcePersonal savings SourcePrivately sponsored SourceProvincial Disability Support Program (e.g.,ODSP, etc.) SourceScholarship(s) SourceSelf-employment SourceSocial assistance/welfare SourceSpouse/parent employment income SourceTraining allowance
    /formula "splitup(Source)".


    its visible to have a support excel doc with concat and texjoin formulas and run it all at once for all multple picklist fields. 
    thank you John.
    Kamal.



    ------------------------------
    Tolife Tolife
    ------------------------------



  • 6.  RE: splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Wed June 02, 2021 09:17 AM
    That is basically correct, except your Result list needs to use legal SPSS variable names.  You can't have blanks in variable names (and are limited to 64 bytes in a name) so step 3 needs to be revised.






  • 7.  RE: splitting value from one variable (multiple values in one variable) to multiple variables

    Posted Mon June 07, 2021 11:07 AM
    Learned. Thank you @Jon Peck
    Highly appreciated.
    Kamal​

    ------------------------------
    Tolife Tolife
    ------------------------------