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

sas-innovate-2024.png

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.

 

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.

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
  • 5 replies
  • 708 views
  • 2 likes
  • 3 in conversation