Dear listmembers,
I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen |
Juergen -
The syntax below does what you want. STRING Newvar(A30). COMPUTE Newvar=CONCAT( LTRIM(V1),LTRIM(V2),LTRIM(V3),LTRIM(V4),LTRIM(V5) ). EXECUTE Thanks. Edward. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 9:51 AM To: [hidden email] Subject: Concatenate values of string variables Dear listmembers, I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen |
In reply to this post by Juergen Pueschel
Juergen -
Below is an alternative solution to you question ( I prefer this ) STRING Newvar(A30). COMPUTE Newvar=Replace((CONCAT( v1 to v5 )) ," ",""). EXECUTE Thanks. Edward. -----Original Message----- From: Edward Boadi Sent: Wednesday, November 22, 2006 10:46 AM To: 'Juergen Pueschel'; [hidden email] Subject: RE: Concatenate values of string variables Juergen - The syntax below does what you want. STRING Newvar(A30). COMPUTE Newvar=CONCAT( LTRIM(V1),LTRIM(V2),LTRIM(V3),LTRIM(V4),LTRIM(V5) ). EXECUTE Thanks. Edward. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 9:51 AM To: [hidden email] Subject: Concatenate values of string variables Dear listmembers, I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen |
In reply to this post by Juergen Pueschel
Dear Edward,
it works. Thank you! A further question: is it possible to include the '&' into the string so that the result looks like: aa & bb & cc & dd & ee ? Regards Jürgen On Wed, 22 Nov 2006 10:45:31 -0500, Edward Boadi <[hidden email]> wrote: >Juergen - > >The syntax below does what you want. > >STRING Newvar(A30). >COMPUTE Newvar=CONCAT( LTRIM(V1),LTRIM(V2),LTRIM(V3),LTRIM(V4),LTRIM(V5) ). >EXECUTE > > >Thanks. >Edward. > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of >Juergen Pueschel >Sent: Wednesday, November 22, 2006 9:51 AM >To: [hidden email] >Subject: Concatenate values of string variables > > >Dear listmembers, > >I would like to concatenate the values of 5 string-variables in one new >variable. Variables with no values should not be concatenated with the >other variables. > >For example: > >V1 V2 V3 V4 V5 Newvar > >aa bb cc dd ee aa & bb & cc & dd & ee >aa cc ee aa & cc & ee >aa ee aa & ee > ee ee > > >Juergen |
In reply to this post by Juergen Pueschel
If you REALLY want the ampersands (&) between each variable, this
works... string newvar (A25). compute newvar=concat(v1," & ",V2," & ",V3," & ",V4," & ",V5). compute newvar=replace(newvar," &",""). if (substr(newvar,length(rtrim(newvar))-1,2)=" &") newvar=(substr(newvar2,1,length(rtrim(newvar2)))). if (substr(newvar,1,5)=" & ") newvar=substr(newvar,6). exe. Let me know if you have any questions. Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 8:51 AM To: [hidden email] Subject: [SPSSX-L] Concatenate values of string variables Dear listmembers, I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by Juergen Pueschel
Well, if you really need the values separated by spaces and ampersands:
*create some sample data. data list list (",") /v1 v2 v3 v4 v5 (5a2). begin data aa,bb,cc,dd,ee aa,,cc,,ee aa,,,,ee ,,,,ee end data. *real code starts here. string newvar (a30). do repeat x=v1 to v5. if x <> ' ' newvar=concat(rtrim(newvar), rtrim(x), ' & '). end repeat. compute newvar=replace(newvar, '&', '& '). compute newvar=substr(newvar, 1, rindex(newvar, '&')-1). There may be a less convoluted solution, but this should work. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 8:51 AM To: [hidden email] Subject: Concatenate values of string variables Dear listmembers, I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen |
In reply to this post by Juergen Pueschel
Dear Melissa,
thanks for the (good) idea. But the replace-command doesn't work, because my SPSS-Version is 12.0. Do you have any other suggestions to include the ampersands? Best regards Juergen On Wed, 22 Nov 2006 10:19:23 -0600, Melissa Ives <[hidden email]> wrote: >If you REALLY want the ampersands (&) between each variable, this >works... > >string newvar (A25). >compute newvar=concat(v1," & ",V2," & ",V3," & ",V4," & ",V5). >compute newvar=replace(newvar," &",""). >if (substr(newvar,length(rtrim(newvar))-1,2)=" &") >newvar=(substr(newvar2,1,length(rtrim(newvar2)))). >if (substr(newvar,1,5)=" & ") newvar=substr(newvar,6). >exe. > >Let me know if you have any questions. > >Melissa > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of >Juergen Pueschel >Sent: Wednesday, November 22, 2006 8:51 AM >To: [hidden email] >Subject: [SPSSX-L] Concatenate values of string variables > >Dear listmembers, > >I would like to concatenate the values of 5 string-variables in one new >variable. Variables with no values should not be concatenated with the >other variables. > >For example: > >V1 V2 V3 V4 V5 Newvar > >aa bb cc dd ee aa & bb & cc & dd & ee >aa cc ee aa & cc & ee >aa ee aa & ee > ee ee > > >Juergen > > > >PRIVILEGED AND CONFIDENTIAL INFORMATION >This transmittal and any attachments may contain PRIVILEGED AND >CONFIDENTIAL information and is intended only for the use of the >addressee. If you are not the designated recipient, or an employee >or agent authorized to deliver such transmittals to the designated >recipient, you are hereby notified that any dissemination, >copying or publication of this transmittal is strictly prohibited. If >you have received this transmittal in error, please notify us >immediately by replying to the sender and delete this copy from your >system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by Juergen Pueschel
Oops. Of course there's a less convoluted solution:
string newvar (a30). do repeat x=v1 to v5. if x <> ' ' newvar=concat(rtrim(newvar), ' & ', rtrim(x)). end repeat. That should be all you need. -----Original Message----- From: Oliver, Richard Sent: Wednesday, November 22, 2006 10:43 AM To: 'Juergen Pueschel'; [hidden email] Subject: RE: Concatenate values of string variables Well, if you really need the values separated by spaces and ampersands: *create some sample data. data list list (",") /v1 v2 v3 v4 v5 (5a2). begin data aa,bb,cc,dd,ee aa,,cc,,ee aa,,,,ee ,,,,ee end data. *real code starts here. string newvar (a30). do repeat x=v1 to v5. if x <> ' ' newvar=concat(rtrim(newvar), rtrim(x), ' & '). end repeat. compute newvar=replace(newvar, '&', '& '). compute newvar=substr(newvar, 1, rindex(newvar, '&')-1). There may be a less convoluted solution, but this should work. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 8:51 AM To: [hidden email] Subject: Concatenate values of string variables Dear listmembers, I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen |
In reply to this post by Juergen Pueschel
Hmmm.... I was using 14.
I don't have anything specific, but in general, I would think you could work with combinations of Index, Length, to find the locations of " &", then use concat(substr(before " &",after " &"), but it'd take some testing to get it to work as you'd expect. Melissa -----Original Message----- From: Juergen Pueschel [mailto:[hidden email]] Sent: Wednesday, November 22, 2006 10:45 AM To: [hidden email]; Melissa Ives Cc: Juergen Pueschel Subject: Re: Concatenate values of string variables Dear Melissa, thanks for the (good) idea. But the replace-command doesn't work, because my SPSS-Version is 12.0. Do you have any other suggestions to include the ampersands? Best regards Juergen On Wed, 22 Nov 2006 10:19:23 -0600, Melissa Ives <[hidden email]> wrote: >If you REALLY want the ampersands (&) between each variable, this >works... > >string newvar (A25). >compute newvar=concat(v1," & ",V2," & ",V3," & ",V4," & ",V5). >compute newvar=replace(newvar," &",""). >if (substr(newvar,length(rtrim(newvar))-1,2)=" &") >newvar=(substr(newvar2,1,length(rtrim(newvar2)))). >if (substr(newvar,1,5)=" & ") newvar=substr(newvar,6). >exe. > >Let me know if you have any questions. > >Melissa > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >Of Juergen Pueschel >Sent: Wednesday, November 22, 2006 8:51 AM >To: [hidden email] >Subject: [SPSSX-L] Concatenate values of string variables > >Dear listmembers, > >I would like to concatenate the values of 5 string-variables in one new >variable. Variables with no values should not be concatenated with the >other variables. > >For example: > >V1 V2 V3 V4 V5 Newvar > >aa bb cc dd ee aa & bb & cc & dd & ee >aa cc ee aa & cc & ee >aa ee aa & ee > ee ee > > >Juergen > > > >PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any >attachments may contain PRIVILEGED AND CONFIDENTIAL information and is >intended only for the use of the addressee. If you are not the >designated recipient, or an employee or agent authorized to deliver >such transmittals to the designated recipient, you are hereby notified >that any dissemination, copying or publication of this transmittal is >strictly prohibited. If you have received this transmittal in error, >please notify us immediately by replying to the sender and delete this >copy from your system. You may also call us at (309) 827-6026 for >assistance. PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by Juergen Pueschel
Oops again. You would still need to strip out the extraneous leading ampersand with and spaces with:
newvar=substr(newvar,4). -----Original Message----- From: Oliver, Richard Sent: Wednesday, November 22, 2006 10:47 AM To: Oliver, Richard; 'Juergen Pueschel'; '[hidden email]' Subject: RE: Concatenate values of string variables Oops. Of course there's a less convoluted solution: string newvar (a30). do repeat x=v1 to v5. if x <> ' ' newvar=concat(rtrim(newvar), ' & ', rtrim(x)). end repeat. That should be all you need. -----Original Message----- From: Oliver, Richard Sent: Wednesday, November 22, 2006 10:43 AM To: 'Juergen Pueschel'; [hidden email] Subject: RE: Concatenate values of string variables Well, if you really need the values separated by spaces and ampersands: *create some sample data. data list list (",") /v1 v2 v3 v4 v5 (5a2). begin data aa,bb,cc,dd,ee aa,,cc,,ee aa,,,,ee ,,,,ee end data. *real code starts here. string newvar (a30). do repeat x=v1 to v5. if x <> ' ' newvar=concat(rtrim(newvar), rtrim(x), ' & '). end repeat. compute newvar=replace(newvar, '&', '& '). compute newvar=substr(newvar, 1, rindex(newvar, '&')-1). There may be a less convoluted solution, but this should work. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 8:51 AM To: [hidden email] Subject: Concatenate values of string variables Dear listmembers, I would like to concatenate the values of 5 string-variables in one new variable. Variables with no values should not be concatenated with the other variables. For example: V1 V2 V3 V4 V5 Newvar aa bb cc dd ee aa & bb & cc & dd & ee aa cc ee aa & cc & ee aa ee aa & ee ee ee Juergen |
In reply to this post by Juergen Pueschel
Complete solution without the Replace function:
string newvar (a30). do repeat x=v1 to v5. if x <> ' ' newvar=concat(rtrim(newvar), ' & ', rtrim(x)). end repeat. compute newvar=substr(newvar,4). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Juergen Pueschel Sent: Wednesday, November 22, 2006 10:45 AM To: [hidden email] Subject: Re: Concatenate values of string variables Dear Melissa, thanks for the (good) idea. But the replace-command doesn't work, because my SPSS-Version is 12.0. Do you have any other suggestions to include the ampersands? Best regards Juergen On Wed, 22 Nov 2006 10:19:23 -0600, Melissa Ives <[hidden email]> wrote: >If you REALLY want the ampersands (&) between each variable, this >works... > >string newvar (A25). >compute newvar=concat(v1," & ",V2," & ",V3," & ",V4," & ",V5). >compute newvar=replace(newvar," &",""). >if (substr(newvar,length(rtrim(newvar))-1,2)=" &") >newvar=(substr(newvar2,1,length(rtrim(newvar2)))). >if (substr(newvar,1,5)=" & ") newvar=substr(newvar,6). >exe. > >Let me know if you have any questions. > >Melissa > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >Of Juergen Pueschel >Sent: Wednesday, November 22, 2006 8:51 AM >To: [hidden email] >Subject: [SPSSX-L] Concatenate values of string variables > >Dear listmembers, > >I would like to concatenate the values of 5 string-variables in one new >variable. Variables with no values should not be concatenated with the >other variables. > >For example: > >V1 V2 V3 V4 V5 Newvar > >aa bb cc dd ee aa & bb & cc & dd & ee >aa cc ee aa & cc & ee >aa ee aa & ee > ee ee > > >Juergen > > > >PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any >attachments may contain PRIVILEGED AND CONFIDENTIAL information and is >intended only for the use of the addressee. If you are not the >designated recipient, or an employee or agent authorized to deliver >such transmittals to the designated recipient, you are hereby notified >that any dissemination, copying or publication of this transmittal is >strictly prohibited. If you have received this transmittal in error, >please notify us immediately by replying to the sender and delete this >copy from your system. You may also call us at (309) 827-6026 for >assistance. |
In reply to this post by Juergen Pueschel
Dear Richard,
that's it! Thanks to you all! Juergen On Wed, 22 Nov 2006 10:55:48 -0600, Oliver, Richard <[hidden email]> wrote: >Complete solution without the Replace function: > >string newvar (a30). >do repeat x=v1 to v5. >if x <> ' ' newvar=concat(rtrim(newvar), ' & ', rtrim(x)). >end repeat. >compute newvar=substr(newvar,4). > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of >Sent: Wednesday, November 22, 2006 10:45 AM >To: [hidden email] >Subject: Re: Concatenate values of string variables > >Dear Melissa, >thanks for the (good) idea. >But the replace-command doesn't work, because my SPSS-Version is 12.0. >Do you have any other suggestions to include the ampersands? > >Best regards > >Juergen > > >On Wed, 22 Nov 2006 10:19:23 -0600, Melissa Ives <[hidden email]> > >>If you REALLY want the ampersands (&) between each variable, this >>works... >> >>string newvar (A25). >>compute newvar=concat(v1," & ",V2," & ",V3," & ",V4," & ",V5). >>compute newvar=replace(newvar," &",""). >>if (substr(newvar,length(rtrim(newvar))-1,2)=" &") >>newvar=(substr(newvar2,1,length(rtrim(newvar2)))). >>if (substr(newvar,1,5)=" & ") newvar=substr(newvar,6). >>exe. >> >>Let me know if you have any questions. >> >>Melissa >> >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >>Of Juergen Pueschel >>Sent: Wednesday, November 22, 2006 8:51 AM >>To: [hidden email] >>Subject: [SPSSX-L] Concatenate values of string variables >> >>Dear listmembers, >> >>I would like to concatenate the values of 5 string-variables in one new >>variable. Variables with no values should not be concatenated with the >>other variables. >> >>For example: >> >>V1 V2 V3 V4 V5 Newvar >> >>aa bb cc dd ee aa & bb & cc & dd & ee >>aa cc ee aa & cc & ee >>aa ee aa & ee >> ee ee >> >> >>Juergen >> >> >> >>PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any >>attachments may contain PRIVILEGED AND CONFIDENTIAL information and is >>intended only for the use of the addressee. If you are not the >>designated recipient, or an employee or agent authorized to deliver >>such transmittals to the designated recipient, you are hereby notified >>that any dissemination, copying or publication of this transmittal is >>strictly prohibited. If you have received this transmittal in error, >>please notify us immediately by replying to the sender and delete this >>copy from your system. You may also call us at (309) 827-6026 for >>assistance. |
Free forum by Nabble | Edit this page |