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

Hi,

 

I have a variable (Tel_No) which is number of which has blank spaces such as 14755 555 898 or 01478 658458.

 

Any idea how I remove the blanks from this please? 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Is the variable actually numeric? Or is it character? I suspect the latter

 

data _null_;
    Tel_No    = '14755 555 898';
    newTel_No = compress(Tel_No);
    put newTel_No=;
run;

 

Result;

 

newTel_No=14755555898

 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Is the variable actually numeric? Or is it character? I suspect the latter

 

data _null_;
    Tel_No    = '14755 555 898';
    newTel_No = compress(Tel_No);
    put newTel_No=;
run;

 

Result;

 

newTel_No=14755555898

 

Kurt_Bremser
Super User

This is stored as character, as it should be. Telephone numbers are not used for calculations and can easily exceed SAS numeric precision.

Use the compress() function to remove unwanted characters (e.g. blanks) from strings.

ballardw
Super User

I once upon a time worked for company where we received lots of phone numbers for client contact. We had process that did what you request. Then had lots of "wrong number" or "why are you calling me, I've never had any contact with Company X". It turned out the process of "cleaning" the phone numbers by removing blanks had resulted in non-US country code values being combined with shorter than US phone numbers to create dialing strings that looked like they were in a US state.

 

So you may want to determine what significance any of those spaces might have before removing them.

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
  • 3 replies
  • 2435 views
  • 0 likes
  • 4 in conversation