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

hi,

 

Can someone suggest a code /function to scan string and return num value when:

 

Where any character within string where delimetor is 1 or more space, begin scanning: If contains or is made up of numeric, flag 1. This is to scan string related to addresses.

 

Examples for variable Address1

(i)  145 SAINT-GEORGES #1107

(ii) 12 MIDDLEPORT CRESEN

(iii) 2040 ALGONQUIN RD UNIT114

(iv) BUREAU 106

 

Output

(i) 2 [flags '145' as 1, and flags '#1107' as 1]

(ii) 1 [flags '12' as 1]

(iii) 2

(iv) 1

 

thanks... I'm gonna review Perl and see what i can get.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK. Assuming I understood what you mean.

 

data have;
input;
have=_infile_;
pid=prxparse('/\d+/');
s=1;e=length(_infile_);
n=0;
call prxnext(pid,s,e,_infile_,p,l);
do while(p>0);
 n+1;
 call prxnext(pid,s,e,_infile_,p,l);
end;
keep have n;
cards;
(i)  145 SAINT-GEORGES #1107
(ii) 12 MIDDLEPORT CRESEN
(iii) 2040 ALGONQUIN RD UNIT114
(iv) BUREAU 106
;
run;

proc print noobs;run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

The ANYDIGIT function will do what you want

--
Paige Miller
Ksharp
Super User

OK. Assuming I understood what you mean.

 

data have;
input;
have=_infile_;
pid=prxparse('/\d+/');
s=1;e=length(_infile_);
n=0;
call prxnext(pid,s,e,_infile_,p,l);
do while(p>0);
 n+1;
 call prxnext(pid,s,e,_infile_,p,l);
end;
keep have n;
cards;
(i)  145 SAINT-GEORGES #1107
(ii) 12 MIDDLEPORT CRESEN
(iii) 2040 ALGONQUIN RD UNIT114
(iv) BUREAU 106
;
run;

proc print noobs;run;
brulard
Pyrite | Level 9
hello Mr Ksharp, a quick thank you for your tip! Also, you and others like R9, Astounding, etc.. are a real inspiration to study and practice SAS & coding!
Ksharp
Super User

If you consider non-prx  way, the COUNTW() is the best choice .

 

data have;
input;
have=_infile_;
n=countw(have,,'kd');
keep have n;
cards;
(i)  145 SAINT-GEORGES #1107
(ii) 12 MIDDLEPORT CRESEN
(iii) 2040 ALGONQUIN RD UNIT114
(iv) BUREAU 106
;
run;

proc print noobs;run;
brulard
Pyrite | Level 9
hi Ksharp, thanks this works too

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1535 views
  • 2 likes
  • 3 in conversation