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 (July 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 20 Jul 2005 02:52:18 -0400
Reply-To:   Richard Ristow <wrristow@mindspring.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Richard Ristow <wrristow@mindspring.com>
Subject:   Re: Removing empty string cells and replacing with next variable cell
Comments:   To: Kirsten McKenzie <k.mckenzie@qut.edu.au>
Comments:   cc: Simon Freidin <simonpf@unimelb.edu.au>
In-Reply-To:   <6.2.1.2.2.20050719115719.01e4b3e0@mail.qut.edu.au>
Content-Type:   text/plain; charset="us-ascii"; format=flowed

At 10:06 PM 7/18/2005, Kirsten McKenzie wrote:

>I have five character string data in the format: > D01 D02 D03 D04 >1 A0001 S0002 G0059 >2 G0009 S0350 >3 S0789 S9900 >4 S9913 >I want to remove all empty string cells and move the next variable >cell into the blank cell so it will now appear: > D01 D02 D03 D04 >1 A0001 S0002 G0059 >2 G0009 S0350 >3 S0789 S9900 >4 S9913 >I also want to delete all empty string variables at the end of the >dataset once all blank cells have been replaced.

As to dropping unused variables at the end of the list, I second Simon Freidin's advice to check Raynald Levesque's Web site. (Or, of course, decide it isn't necessary to drop them.) I believe Simon's solution to moving values to close up empty cells has two drawbacks: A.) It doesn't work if there are two or more empty cells contiguous B.) It leaves variable X in the final file.

Below is SPSS draft output for Simon's solution, and an alternative that I believe solves these problems. I think Jan Spousta has posted with this logic, though I can't find the posting at the moment.

GET FILE=TESTDATA. LIST. List Notes |---------------------|--------------------| |Output Created |20 Jul 05 02:47:20 | |---------------------|--------------------| ID D01 D02 D03 D04

1 A0001 S0002 G0059 2 G0009 S0350 3 S0789 S9900 4 S9913 5 T1201 U5342

Number of cases read: 5 Number of cases listed: 5

* Simon Freidin solution . /* moving data across */ vector d=d01 to d04. loop x=1 to 4 if x<4. - do if d(x)=''. . compute d(x)=d(x+1). . compute d(x+1)=''. . compute x=x+1. - end if. end loop. LIST. List Notes |---------------------|--------------------| |Output Created |20 Jul 05 02:47:20 | |---------------------|--------------------| ID D01 D02 D03 D04 X

1 A0001 S0002 G0059 4.00 2 G0009 S0350 4.00 3 S0789 S9900 4.00 4 S9913 4.00 5 T1201 U5342 4.00

Number of cases read: 5 Number of cases listed: 5

* Jan Spousta/Ristow solution . GET FILE=TESTDATA. vector d=d01 to d04. COMPUTE #DEST = 1. LOOP #SRCE = 1 TO 4. - DO IF D(#SRCE) NE ''. . COMPUTE D(#DEST)=D(#SRCE). . COMPUTE #DEST = #DEST + 1. - END IF. END LOOP. LOOP #ZAP = #DEST TO 4. . COMPUTE D(#ZAP) = ''. END LOOP. LIST. List Notes |---------------------|--------------------| |Output Created |20 Jul 05 02:47:22 | |---------------------|--------------------| ID D01 D02 D03 D04

1 A0001 S0002 G0059 2 G0009 S0350 3 S0789 S9900 4 S9913 5 T1201 U5342

Number of cases read: 5 Number of cases listed: 5


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