Eliminate duplicate columns

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Clemens
Posts: 1
Joined: Mon Jul 16, 2012 8:52 am

Eliminate duplicate columns

Hopefully someone can help.

In my SPSS data I have several vectors of 0 and 1 one after another in each line. Each 0 or 1 is in an extra column, but I am interested in vectors of for example 5 numbers. The data looks like this:

10000 01000 01000 01000 10100 01010 01010 00000

As you can see, some vectors are duplicates of the vectors before or after it. I want to eliminate those, move everything else to the left and fill up the line with 0. Like this:

10000 01000 10100 01010 00000 00000 00000 00000
(Each 0 or 1 is in one column.)

How can I do that in SPSS?
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Eliminate duplicate columns

just a hint, there is probably a more elegant way to do this:

1. create varibles with those 5 numbers in a row using concat (numb1, numb2 ... numb5)
2. use if functions to indentify doubles (if numb1 = numb2) and replace the second ones with numbers
if ( numb1 = numb2 ) numb2 = sysmis.
if ( numb2 = numb3 ) numb3 = sysmis.
if ( numb3 = numb4 ) numb4 = sysmis.
if ( numb4 = numb5 ) numb5 = sysmis.
if ( numb2 = numb3 ) numb3 = sysmis.
if ( numb2 = numb4 ) numb4 = sysmis.
if ( numb2 = numb5 ) numb5 = sysmis.
if ( numb3 = numb4 ) numb4 = sysmis.
if ( numb3 = numb5 ) numb5 = sysmis.
if ( numb4 = numb5 ) numb5 = sysmis.
3. use loop to replace sysmis with the next variable
4. replace remaining sysmis with 00000.
5. if you want, split into separate varaibles again.

Who is online

Users browsing this forum: No registered users and 2 guests