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.
Original Message:
Sent: 10/24/2023 2:13:00 PM
From: Barry Shaw
Subject: RE: How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?
Thank you very much Jon.
That worked a treat.
regards
------------------------------
Barry Shaw
------------------------------
Original Message:
Sent: Mon October 23, 2023 04:57 PM
From: Jon Peck
Subject: How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?
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.
Original Message:
Sent: 10/23/2023 2:37:00 PM
From: Barry Shaw
Subject: How do I duplicate rows based on cell contents (cell contains semi-colon seperated data)?
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
------------------------------