DATA Step, Macro, Functions and more

exclude numbers from observations

Accepted Solution Solved
Reply
Regular Contributor
Posts: 199
Accepted Solution

exclude numbers from observations

How do I exclude numbers from an observation?

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

Thank you.


Accepted Solutions
Solution
‎10-26-2011 07:15 PM
PROC Star
Posts: 7,477

exclude numbers from observations

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


All Replies
Valued Guide
Posts: 2,177

exclude numbers from observations

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

Regular Contributor
Posts: 199

exclude numbers from observations

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.

PROC Star
Posts: 7,477

exclude numbers from observations

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

Regular Contributor
Posts: 199

exclude numbers from observations

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

then I lose spaces as well as digits.

Solution
‎10-26-2011 07:15 PM
PROC Star
Posts: 7,477

exclude numbers from observations

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;

Regular Contributor
Posts: 199

exclude numbers from observations

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 186 views
  • 3 likes
  • 3 in conversation