BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SMartin
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
naveen_srini
Quartz | Level 8

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

7 REPLIES 7
naveen_srini
Quartz | Level 8

have you tried using ANYDIGIT function?

naveen_srini
Quartz | Level 8

  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!

jakarman
Barite | Level 11

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 --<-----
naveen_srini
Quartz | Level 8

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

Andygray
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 3990 views
  • 2 likes
  • 4 in conversation