Date: Wed, 22 Nov 2006 10:51:50 -0600
Reply-To: "Oliver, Richard" <roliver@spss.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Oliver, Richard" <roliver@spss.com>
Subject: Re: Concatenate values of string variables
Content-Type: text/plain; charset="us-ascii"
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'; 'SPSSX-L@LISTSERV.UGA.EDU'
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'; SPSSX-L@LISTSERV.UGA.EDU
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:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Juergen Pueschel
Sent: Wednesday, November 22, 2006 8:51 AM
To: SPSSX-L@LISTSERV.UGA.EDU
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
|