SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?

    Posted Mon October 23, 2023 04:48 PM
      |   view attached

    Can anyone provide the syntax required for the following:

    Regarding the attached, I want to duplicate rows based on the content of Column B. I'd like a separate row for each "Person" in the cell?


    In case the attachment can't be seen, I need an SPSS syntax solution to the problem as outlined in the following link:

    https://community.fabric.microsoft.com/t5/Desktop/How-do-I-duplicate-rows-based-on-cell-contents-cell-contains/m-p/200606

    Many thanks



    ------------------------------
    Barry Shaw
    ------------------------------



  • 2.  RE: How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?

    Posted Mon October 23, 2023 04:58 PM
    First, create a variable for each segment of the second variable.  You can do this with a DO IF loop.  Then use VARSTOCASES to create a case for each instance.





  • 3.  RE: How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?

    Posted Tue October 24, 2023 02:13 PM

    Thank you very much Jon. 

    That worked a treat. 

    regards



    ------------------------------
    Barry Shaw
    ------------------------------



  • 4.  RE: How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?

    Posted Fri October 27, 2023 02:39 PM

    I think this would work as well and not require creating additional variables or manual intervention. I hope this helps.

     

    data list / contacts 1-32 (a).

    begin data.

    PersA;PersB

    PersC;PersD ;

    end data.

     

    compute lencontacts = LENGTH(ltrim(rtrim(contacts))).

     

    string name (a64).

    compute start = 1.

     

    loop i = 1 to lencontacts.

    do if (char.subsrt(contacts,i,1) = ";" or i = lencontacts).

    do if (i < lencontacts).

    compute name = ltrim(char.substr(contacts,start,i-start)).

    else if (char.substr(contacts,lencontacts,1) = ";").

    compute  name = ltrim(char.substr(contacts,start,i-start)).

    else.

    compute  name = ltrim(char.substr(contacts,start,i-start+1)).

    end if.

    xsave outfile = "c:\temp\test\extractor.sav".

    compute start = i+1.

    end if.

    end loop.

     

    get file = "c:\temp\test\extractor.sav".

    list var = all.



    This e-mail and any files transmitted with it may contain privileged or confidential information. It is solely for use by the individual for whom it is intended, even if addressed incorrectly. If you received this e-mail in error, please notify the sender; do not disclose, copy, distribute, or take any action in reliance on the contents of this information; and delete it from your system. Any other use of this e-mail is prohibited.


    Thank you for your compliance.