LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2001)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 9 Oct 2001 21:10:17 -0400
Reply-To:     Raynald Levesque <rlevesque@VIDEOTRON.CA>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Raynald Levesque <rlevesque@VIDEOTRON.CA>
Subject:      Re: Converting a column of data into a string
In-Reply-To:  <001501c15070$6483e810$82121018@CORPNT.NET>
Content-Type: text/plain; charset="iso-8859-1"

Hi Mark

The following syntax works for any 'reasonable' n (the limit comes from the length of newvar which is limited to 255 characters).

DATA LIST LIST /var1(A8). BEGIN DATA . x1 . . x2 x3 . x4 . . END DATA. LIST.

COMPUTE dummy=1. SAVE OUTFILE='c:\temp\mydata.sav'.

SELECT IF LTRIM(RTRIM(var1))<>".". COMPUTE idx=$CASENUM. STRING newvar(A255). DO IF idx=1. COMPUTE newvar=var1. ELSE. COMPUTE newvar=CONCAT(RTRIM(LAG(newvar))," ",var1). END IF. EXECUTE.

COMPUTE dummy=1. ADD FILES FILE=* /BY=dummy /LAST=last. EXECUTE. SELECT IF last=1. SAVE OUTFILE='c:\temp\mystring.sav'. GET FILE='c:\temp\mydata.sav'. MATCH FILES FILE=* /TABLE='c:\temp\mystring.sav' /BY dummy. * Clean up. MATCH FILES FILE=* /DROP=dummy idx. EXECUTE.

HTH

Raynald Levesque rlevesque@videotron.ca Visit my SPSS Pages http://pages.infinit.net/rlevesqu/index.htm

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Mark Scarr Sent: Monday, October 08, 2001 11:14 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Converting a column of data into a string

Hi All,

Yet another question (apologies)! Again I have been unable to find help online :(

I have a string variable var1 that may contain entries x_1 to x_n interspersed with missing values (n is unknown in advance). I would like to create a new constant string variable newvar which is simply a concatenation of all the non sysmissing values in var1.

var1 newvar . 'x1 x2 x3 x4' x1 'x1 x2 x3 x4' . 'x1 x2 x3 x4' . 'x1 x2 x3 x4' x2 'x1 x2 x3 x4' x3 'x1 x2 x3 x4' . 'x1 x2 x3 x4' x4 'x1 x2 x3 x4' . 'x1 x2 x3 x4' . 'x1 x2 x3 x4'

Many thanks in advance

Mark.


Back to: Top of message | Previous page | Main SPSSX-L page