Recode binary string into numeric variable

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

pschel
Posts: 1
Joined: Mon Sep 12, 2011 2:56 pm

Recode binary string into numeric variable

Postby pschel » Mon Sep 12, 2011 3:15 pm

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
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Recode binary string into numeric variable

Postby GerineL » Mon Sep 12, 2011 3:35 pm

make it a string, take a substring for each value and write out your if statement.

Who is online

Users browsing this forum: No registered users and 2 guests

cron