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.
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;
The ANYDIGIT function will do what you want
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.