BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shmuel
Garnet | Level 18

I'm trying to learn the PRX functions.

 

I want to extract the area_code from a given phone number.

Attached is my log showing the code and the result I got - not fitting

to the expected area code '03'.

73         data _null_;
 74             length area_code $3;
 75             phone = '03-6789021';
 76             prx_id = prxparse("/\(d+\)D/");
 77             pos = prxmatch(prx_ID, phone);
 78             area_code = prxposn(prx_id, 1, phone);
 79             put prx_id= pos= area_code=;
 80         run;
 
 prx_id=1 pos=0 area_code= 
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds

 

The expression should look for any number of digits until first non digit character:

 

Please fix my code and if possible some explanation to my error.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

The problem is with the escape character ("\"). "\(" and "\)" look for the actual parantheses in the expression. And "d+" looks for the letter "d", repeated one or more times.

 

Try "/(\d+)\D/" instead.

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

The problem is with the escape character ("\"). "\(" and "\)" look for the actual parantheses in the expression. And "d+" looks for the letter "d", repeated one or more times.

 

Try "/(\d+)\D/" instead.

Shmuel
Garnet | Level 18

@s_lassen , thanks very much, it works as expected.

Looking at the solution helped me to understand better the logic of creating the right expression.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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