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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 674 views
  • 2 likes
  • 3 in conversation