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

Hi, I'm working on a problem that wants me to create an advanced filter for a 'Phone_number" variable, that removes the extension at the beginning of the phone numbers, making them 7 digit numbers. The extensions are +61(2)', '+61(3)', and '+61(5)'  

 

Here is what I've been trying : COMPRESS(t1.Phone_Number, "+61(2)", "+61(3)", "+61(5)")

 

Could someone please tell me what I'm doing wrong and provide the correct FUNCTION to use in this scenario.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

You could try pasting the relevant statement into the QueryBuilder as a new computed column - I guess it is SQL:

transtrn(phone, '+61(2)', '') as phone_new

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

COMPRESS removes blanks. Here is one way:

data _null_;
  phone = '+61(2)1234567';
  phone = transtrn(phone, '+61(2)', '');
  put _all_;
run;
BrockJarvie
Obsidian | Level 7

And this will work as an advanced filter to a pre-existing column in the Querybuilder?

SASKiwi
PROC Star

A filter selects rows it doesn't transform values so no.

BrockJarvie
Obsidian | Level 7

So are you suggesting I make a new computed column? 

How would you attempt it?

SASKiwi
PROC Star

You could try pasting the relevant statement into the QueryBuilder as a new computed column - I guess it is SQL:

transtrn(phone, '+61(2)', '') as phone_new
TomKari
Onyx | Level 15

You should be able to do it in a generalized way using regular expressions. Using this code to create some data:

 

data Have;
	length Phone_Number $20;
	input Phone_Number;
	cards;
+61(2)1234567
+61(3)9876543
+61(5)2223333
run;

create a new query on the data. Set up a new Advanced Expression, and in the "Enter an expression:" box, copy and paste:

prxchange("s/(\+[[:digit:]]+\([[:digit:]]\))([[:digit:]]+)/$2/", -1, Phone_Number)

Tom

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 823 views
  • 1 like
  • 3 in conversation