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

How do I exclude numbers from an observation?

For example, I want "Brown, Jack" instead of "Brown, Jack 01".

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You'll have to provide an example with data and code where that happens.  It doesn't happen in the following test:

data have;

  length name $30;

  input;

  name=_infile_;

  cards;

Smith,     John 12

Jones,   John 12

Smith, Mary 14

Howard, Wilburt 3rd 19

;

data want;

  set have;

  name=compress(name,,'d');

run;

View solution in original post

6 REPLIES 6
Peter_C
Rhodochrosite | Level 12

have a look at the modifiers for the compress() function

gzr2mz39
Quartz | Level 8

The modifier 'ak' removes the numbers, but I lose the comma.

If I use 'd' I lose all spaces.

How do I keep spaces and commas?

Thank you.

art297
Opal | Level 21

Don't use the k modifier.  Only use the d modifier.  That way you will drop all of the digits.

gzr2mz39
Quartz | Level 8

If I use this  compress(reported_by,'','d')

then I lose spaces as well as digits.

art297
Opal | Level 21

You'll have to provide an example with data and code where that happens.  It doesn't happen in the following test:

data have;

  length name $30;

  input;

  name=_infile_;

  cards;

Smith,     John 12

Jones,   John 12

Smith, Mary 14

Howard, Wilburt 3rd 19

;

data want;

  set have;

  name=compress(name,,'d');

run;

gzr2mz39
Quartz | Level 8

I changed compress(reported_by,'','d') to compress(reported_by,,'d'). Thank you.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 879 views
  • 3 likes
  • 3 in conversation