SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

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:

  • BIPAP (BIPHASIC POSITIVE AIRWAY PRESSURE) DEPENDENCE, CHRONIC RESPIRATORY FAILURE
  • CHRONIC RESPIRATORY FAILURE & VENT/TRACH DEPENDENT

I expect the result is shown below.

  • (),
  • & / 
14 REPLIES 14
PaigeMiller
Diamond | Level 26

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.

 

--
Paige Miller
ybz12003
Rhodochrosite | Level 12
The link is not working...
PaigeMiller
Diamond | Level 26

Works for me. What error do you get?

--
Paige Miller
ybz12003
Rhodochrosite | Level 12
Page Not Found
Tom
Super User Tom
Super User

But you only asked it to remove that single character with the hexcode of A0.

 

COMPRESS(source ,< characters> ,< modifier(s)>)

ybz12003
Rhodochrosite | Level 12
What's X for?
Tom
Super User Tom
Super User

@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. 

ybz12003
Rhodochrosite | Level 12
I got the code from the someone else.
ybz12003
Rhodochrosite | Level 12

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');
Tom
Super User Tom
Super User

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)>)

PaigeMiller
Diamond | Level 26

Why do you write in your original message about removing numbers, and then give no example where numbers should be removed?

--
Paige Miller
ybz12003
Rhodochrosite | Level 12
Because the actual data contain numbers and charater.
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 14 replies
  • 4002 views
  • 0 likes
  • 4 in conversation