Help using Base SAS procedures

Splitting street from number (split string into two variables)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

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

I was thinking about substr() and scan() but I couldn't found a good advise on google.

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

View solution in original post


All Replies
Frequent Contributor
Posts: 115

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

have you tried using ANYDIGIT function?

Valued Guide
Posts: 3,208

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!

Valued Guide
Posts: 3,208

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!!!

Contributor
Posts: 56

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

Please mark the question as answered and award appropriate points for correct and helpful answers to Naveen and Jaap. Just courtesy!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 659 views
  • 1 like
  • 4 in conversation