Hello,
I try to use "compress" to remove the letter or number from the string. Somehow it didn't work. Please let me know how to fix it.
ID_=compress(strip(upcase(ID)),'A0'x);
Below is some sample strings:
I expect the result is shown below.
This is a great situation where you should just look at the documentation. What option of the COMPRESS function removes numbers? What option of the COMPRESS function removes letters?
Documentation: https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n0fcshr0ir3h73n1b845c4aq58hz.htm
I'll get you started: remove letters
ID_=compress(strip(ID), ,'a');
I assign you the homework to figure out how to remove numbers.
Works for me. What error do you get?
Works for me also. From where are you accessing the internet? Maybe a badly configured firewall interferes.
But you only asked it to remove that single character with the hexcode of A0.
COMPRESS(source ,< characters> ,< modifier(s)>)
@ybz12003 wrote:
What's X for?
Why are you asking me? You posted the code:
ID_=compress(strip(upcase(ID)),'A0'x);
This code is requesting that any instances of the character represented by the hexadecimal code A0 be removed. That code is frequently used on Web pages as a non-breaking space so that multiple word phrases are not wrapped in the middle.
The letter X after a quoted string indicts a string literal in hexadecimal notation. Just like the letter D after a quoted string indicates a date literal in a style that the DATE informat can interpret.
So, it seems like the code below works for the result I want, which needs to have three arguments instead of two.
ID_=compress(strip(upcase(ID_)), , 'A');
But I still don't understand why two arguments are not working.
ID_=compress(strip(upcase(ID_)), 'A');
The first one is using the modifier A. The second one is just asking to remove the capital letter A.
COMPRESS(source ,< characters> ,< modifier(s)>)
Why do you write in your original message about removing numbers, and then give no example where numbers should be removed?
@ybz12003 wrote:
Because the actual data contain numbers and charater.
So to help all of us in the future, from now on, please give us representative examples that illustrate the ENTIRE problem; in this case, examples involving numbers, and examples involving characters.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.