## Splitting street from number (split string into two variables)

Solved
Occasional Contributor
Posts: 12

# Splitting street from number (split string into two variables)

Hello,

I have a variable with street and number in one string. I would like to split them into two variables:

data example;

input street_number \$30.;

datalines;

Limburger Str. 15a

Genter Str. 1

Schanzenstrasse 12 b

Hollunder Weg 92

;

run;

I am looking for a function which can split - if the first character is a number

My output should look like:

Street                      Number

Limburger Str.           15a

Genter Str.               1

Schanzenstrasse      12 b

Hollunder Weg          92

Best Regards

Silke

Accepted Solutions
Solution
‎04-15-2015 06:07 AM
Frequent Contributor
Posts: 115

## Re: Splitting street from number (split string into two variables)

data example;
input street_number & :\$50.;
datalines;
Limburger Str. 15a
Genter Str. 1
Schanzenstrasse 12 b
Hollunder Weg 92
;

run;

data solution;
set example;
street=substr(street_number,1,anydigit(street_number)-1);
Number=substr(street_number,anydigit(street_number),length(street_number));
run;

Regards,

Naveen Srinivasan

L&T Infotech

All Replies
Frequent Contributor
Posts: 115

## Re: Splitting street from number (split string into two variables)

have you tried using ANYDIGIT function?

Posts: 3,215

## Re: Splitting street from number (split string into two variables)

PRX fucntions? http://www2.sas.com/proceedings/forum2007/223-2007.pdf

---->-- ja karman --<-----
Frequent Contributor
Posts: 115

## Re: Splitting street from number (split string into two variables)

Sir, Forgive me, I trust and totally agree PRX will work seamlessly, but I am not even anywhere close or  to your level of expertise, so I still have to learn PRX from the very begining. I really appreciate sharing the doc, does the really cover from the very basic to considerable advance level of PRX functions and should i have to learn perl scripting before learning to use PRX functions, If so, that sounds very daunting.:smileyconfused:

BTW, I have taken a lot of your help in the past from other posts, although never had a chance to thank personally. Cheers!

Posts: 3,215

## Re: Splitting street from number (split string into two variables)

Naveen for PRX just take some sample as posted and do a trial for an easy problem when that one succeeds and understood go for the more difficult ones.
You do not need to learn the PERL just the PRX part. Samples are more easy to follow than the docs.

SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition  (reference PRX ,metadatachars)

SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition (PRXPARSE doc)   the one that does the PRX compilation. Preferable needed only once in a datastep

---->-- ja karman --<-----
Solution
‎04-15-2015 06:07 AM
Frequent Contributor
Posts: 115

## Re: Splitting street from number (split string into two variables)

data example;
input street_number & :\$50.;
datalines;
Limburger Str. 15a
Genter Str. 1
Schanzenstrasse 12 b
Hollunder Weg 92
;

run;

data solution;
set example;
street=substr(street_number,1,anydigit(street_number)-1);
Number=substr(street_number,anydigit(street_number),length(street_number));
run;

Regards,

Naveen Srinivasan

L&T Infotech

Occasional Contributor
Posts: 12

## Re: Splitting street from number (split string into two variables)

Thank you!!!

Frequent Contributor
Posts: 75