BookmarkSubscribeRSS Feed
6 REPLIES 6
Haikuo
Onyx | Level 15

You will probably need some Regular expression:

data have;

  input email :$char100.;

  cards;

  ------------------------------------@GMAIL.COM

-------------@-------------.COM

-------------@YAHOO.COM

------------@EMC.COM

----------@HOTMAIL.COM

----------@YAHOO.COM

---------@PRTC.NET

---------@--.COM

--------@AOL.COM

abc@gmail.com

mike-smith@tg-aol.com

;

data want;

set have;

  if prxmatch("/^-+@/",email) then ind=1;

run;

proc print;run;

Haikuo

Astounding
PROC Star

One way:

proc freq data=have;

tables email;

where index(email, '----');

run;

It will print a table based on any email addresses that contain four dashes in a row, anywhere within the address.  If you want to cut it to less than 4, that's up to you.  You know your data best.

Good luck.

Haikuo
Onyx | Level 15

I had to ask, what if you want to keep:

abc----xyz@gmail.com

but to drop:

----@gmail.com?

I still think the Regular expression is the way to go, at least for the first step.

my 2 cents,

Haikuo

Astounding
PROC Star

I suppose I could switch from this:

index(email, '----')

to this:

index(email, '-@')

art297
Opal | Level 21

: Since you wanted strings that start with any number of hyphens, then followed with an @, I'll suggest adding one more character to Haikuo's code.  The ^ at the beginning forces the match to have occurred at the start of the string:

data have;

  informat email $50.;

  input email;

  cards;

------------------------------------@GMAIL.COM

-------------@-------------.COM

-------------@YAHOO.COM

------------@EMC.COM

x----------@HOTMAIL.COM

----------@YAHOO.COM

---------@PRTC.NET

---------@--.COM

--------@AOL.COM

abc@gmail.com

;

data want;

  set have;;

  if prxmatch("/^-+@/",email) then ind=1;

run;

DBailey
Lapis Lazuli | Level 10

DATA WANT;

SET HAVE;

if index(email,'@')-1 = countc(substr(email,1,index(email,'@')-1),'-');

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2170 views
  • 1 like
  • 5 in conversation