DATA Step, Macro, Functions and more

Valid email address:

Reply
Super Contributor
Posts: 673

Valid email address:

Respected Advisor
Posts: 3,156

Re: Valid email address:

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

Super User
Posts: 5,518

Re: Valid email address:

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.

Respected Advisor
Posts: 3,156

Re: Valid email address:

Posted in reply to Astounding

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

Super User
Posts: 5,518

Re: Valid email address:

I suppose I could switch from this:

index(email, '----')

to this:

index(email, '-@')

PROC Star
Posts: 7,492

Re: Valid email address:

: 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;

Super Contributor
Posts: 578

Re: Valid email address:

DATA WANT;

SET HAVE;

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

run;

Ask a Question
Discussion stats
  • 6 replies
  • 264 views
  • 1 like
  • 5 in conversation