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: 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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 881 views
  • 1 like
  • 3 in conversation