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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.