Recoding a string which contains a certain phrase

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

louis4702
Posts: 1
Joined: Mon Jan 28, 2013 3:29 pm

Recoding a string which contains a certain phrase

Postby louis4702 » Mon Jan 28, 2013 3:34 pm

I'm looking to recode a string variable which contains UK postcodes into a new numeric variable with five categories. The categories are the same for whole postcode areas so, for example, is it possible to recode RG40 1ST and RG40 3SA the same, without having to type every single full postcode into the syntax?

Thanks.
JonPedersen
Posts: 119
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Recoding a string which contains a certain phrase

Postby JonPedersen » Mon Jan 28, 2013 9:15 pm

Hi,
one way to do it is to use SUBSTR, i.e.
do if char.substr(oldvar,1,4)='RT40'.
compute region=1.
else if char.substr(oldvar,1,4)='RT50'.
compute region=2.
else if etc....
....
end if.
you can also use autorecode, and then an ordinary recode, but then you have to inspect the result of the autorecode before you do the recode.
hth
Jon

Who is online

Users browsing this forum: No registered users and 1 guest

cron