Good morning. This is my first post on this forum. My problem is perhaps simple, but I'm not an experienced programmer or SPSS syntax writer. I'd like to recode a string with six places and all characters equal to 0 or 1 into a numeric variable with values 1-5.

The original string includes such values as:

'100000'

'100001'

'001000'

'001011'

and, theoretically, any variation of ones and zeros in this pattern.

The interpretive rubric is as follows:

I want to recode all the values beginning with one into the number 4,

all values in which the value of the first place is zero and the fourth place is one into the number 3,

all values in which the value of the first place is zero and the third or fifth place is one into the number 2,

all values in which the value of the first place is zero and the second place is one into the number 1,

all values in which the value of the sixth place is one and every other place is zero into the number 5,

all values in which all places are zero into the system missing value,

and all other values into the number 0.

or,

'1xxxxx' = 4

'0xx1xx' = 3

'0x1xxx' and 0xxx1x = 2

'01xxxx' = 1

'000001' = 5

'000000' = $SYSMIS

ELSE = 0 (to flag data/syntax problems)

Has anyone done anything similar to this?

Thanks!

--Peter