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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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