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?
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
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
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.
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.
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!
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.