Flag words containing or made of numeric

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 123
Accepted Solution

Flag words containing or made of numeric

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.


Accepted Solutions
Solution
‎03-27-2018 09:21 AM
Super User
Posts: 10,770

Re: Flag words containing or made of numeric

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


All Replies
Respected Advisor
Posts: 3,000

Re: Flag words containing or made of numeric

The ANYDIGIT function will do what you want

--
Paige Miller
Solution
‎03-27-2018 09:21 AM
Super User
Posts: 10,770

Re: Flag words containing or made of numeric

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;
Frequent Contributor
Posts: 123

Re: Flag words containing or made of numeric

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!
Super User
Posts: 10,770

Re: Flag words containing or made of numeric

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;
Frequent Contributor
Posts: 123

Re: Flag words containing or made of numeric

hi Ksharp, thanks this works too
☑ This topic is solved.

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

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