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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 547 views
  • 3 likes
  • 2 in conversation