## SUBSTRING

Solved
Super Contributor
Posts: 1,041

# SUBSTRING

Hello,

Here below I have a column called EMAIL

Of all the emails we wanted to check how many times gmail was wrongly entered....

Since GMAIL starts with the letter "G" we can take all the words starting with letter G after @ in the email adress??????

HAVE:

apple@gmail.com

buffalo@gmail.com

cat@gunail.com

dog@GMAI.COM

elephant@gmail.con

goat@yahoo.com

horse@hotmail.com

kangaroo@gnail.com

horse@gmi.com

WANT:

gmail.com    2

gunail.com   1

GMAI.COM   1

gmail.con      1

gnail.com      1

gmi.com       1

Accepted Solutions
Solution
‎03-21-2016 02:50 PM
Super User
Posts: 13,556

## Re: SUBSTRING

I will suggest that limiting your search to @g is insufficient. You may well have enteries like Johh@jmail.com or John@fmail.com or ...

I might be tempted to do something like:

``````data have;
length email \$40.;
input email;
isp =upcase(scan(email,2,"@"));
distance = complev('gmail.com',isp,'i');
datalines;
apple@gmail.com
buffalo@gmail.com
cat@gunail.com
dog@GMAI.COM
elephant@gmail.con
goat@yahoo.com
horse@hotmail.com
kangaroo@gnail.com
horse@gmi.com
john@tmail.com
john@jmail.com
;

proc tabulate data=have;
class distance isp;
table distance*isp,n;
run;
``````

The "distance" value when small means the spelling is "close" to Gmail.com.

Note that I did add in couple of other possibly typos.

All Replies
Super User
Posts: 5,881

## Re: SUBSTRING

Combine scan and substr functions.
Data never sleeps
Solution
‎03-21-2016 02:50 PM
Super User
Posts: 13,556

## Re: SUBSTRING

I will suggest that limiting your search to @g is insufficient. You may well have enteries like Johh@jmail.com or John@fmail.com or ...

I might be tempted to do something like:

``````data have;
length email \$40.;
input email;
isp =upcase(scan(email,2,"@"));
distance = complev('gmail.com',isp,'i');
datalines;
apple@gmail.com
buffalo@gmail.com
cat@gunail.com
dog@GMAI.COM
elephant@gmail.con
goat@yahoo.com
horse@hotmail.com
kangaroo@gnail.com
horse@gmi.com
john@tmail.com
john@jmail.com
;

proc tabulate data=have;
class distance isp;
table distance*isp,n;
run;
``````

The "distance" value when small means the spelling is "close" to Gmail.com.

Note that I did add in couple of other possibly typos.

🔒 This topic is solved and locked.