turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Subsetting data

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-14-2017 10:34 AM

Hello

I am trying to subset observations that are 9 digits and in AAA-SS-XXXX format (e.g. 132980984). I found some variations including values that are fewer than 9 digits, missing (.), 0, and some values that doesn't have any posted meaning (e.g. 999999999 or 888888888) So far, I am considering anything except AAA-SS-XXXX as being unknown. Can someone help me figure out how to do this?

Thank you!

Accepted Solutions

Solution

09-14-2017
11:45 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kiko

09-14-2017 11:40 AM

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kiko

09-14-2017 10:44 AM

What do you have so far?

Are you looking for help with a regular expression or using BASE SAS functions?

Regular Expressions is likely faster, but it's not easy to understand or modify.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kiko

09-14-2017 10:56 AM

Please clarify what this means:

I am trying to subset observations that are 9 digits and in AAA-SS-XXXX format (e.g. 132980984).

I would expect the example to look like 132-98-0984 from your "format" comment. By anychance has the SSN format been assigned to this variable?

Is this variable character or numeric? Your statement of values of . implies numeric but I've been fooled before.

You might post some example values and what you want as a result for those.

If some values are out of expected ranges such as your 999999999 then you should provide expected ranges.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

09-14-2017 11:31 AM

Hello-

Sorry for the confusion- yes, they are SSN and it is numeric. Here are a few examples:

209876896

498304981

0

54376548

4326583

I basically want to grab every observation that is 9 digits thus exclude the followings:

0 / '.'/ 999999999/ 888888888

I also found a few cases that are 9 digits, but start with 888 which I am not sure how to deal with, but would like to include them for now.

Thank you!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kiko

09-14-2017 11:43 AM

In a data step:

if variablename in (. 0 99999999 888888888) then <do what ever>.

If you are actually creating a subset data with these values then

data want;

set have;

if variablename in (. 0 99999999 888888888);

run;

to exclude:

data want;

set have;

if variablename not in (. 0 99999999 888888888);

run;

Or use a dataset option where clause (where=( variablename not in (. 0 99999999 888888888))) if you don't want to create a separate data set but use the same data set for analysis.

Solution

09-14-2017
11:45 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kiko

09-14-2017 11:40 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

09-14-2017 11:44 AM

Thank you both! super helpful