BookmarkSubscribeRSS Feed
sas_lak
Quartz | Level 8

Hi All,

Can any one help me to re correct the below data into proper format

Ex:-

XXX@GMMIL.COM           ----------------------  @GMAIL.COM

YYY@GMIL.COM

ZZZ@GMAILL.COM

XXX@YAHOOO.COM     ----------------------   @YAHOO.COM

YYY@YHOO.COM

ZZZ@YAHOHO.COM

XXX@HOOTMAIL.COM   ---------------------- @ HOTMAIL.COM

YYY@HAATMAIL.COM

ZZZ@HITMAIL.COM

I tried to convert into proper format using SPEDIS Function but am not able to get it.

2 REPLIES 2
andreas_lds
Jade | Level 19

Please post the code you already have.

Relying upon a single function result to alter an EMail-address can cause false replacements.

Just an idea:

data work.want;
   set work.have;
   length
      DomainList $ 100
      Domain $ 20
      i minId minCost cost 8
      NewEMail $ 100
   ;

   /* List of valid domains, if the list is longer: store it in another dataset and use a hash-object */

   retain DomainList "GMAIL.COM YAHOO.COM HOTMAIL.COM";

   /* Anything on the left of @ is unimportant */

   Domain = scan(Email, 2, '@');
   minCost = constant('BIG');

   /*

   do i = 1 to countw(DomainList, ' ');
      cost = spedis(Domain, scan(DomainList, i, ' '));

      if cost < minCost then do;
         minCost = cost;
         minId = i;
      end;
   end;

   NewEMail = catx('@', scan(Email, 1, '@'), scan(DomainList, minId, ' '));
run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Well, if the first letter is always indicative, then just check that:

data have;
  length email $200.;
  input email $;
cards;
XXX@GMMIL.COM
YYY@GMIL.COM
ZZZ@GMAILL.COM
XXX@YAHOOO.COM
YYY@YHOO.COM
ZZZ@YAHOHO.COM
XXX@HOOTMAIL.COM
YYY@HAATMAIL.COM
ZZZ@HITMAIL.COM
;
run;

data want;
  length newmail $200.;
  set have;
  select(substr(scan(scan(email,2,'@'),1,'.'),1,1));
    when ('G') newmail=scan(email,1,'@')||"@GMAIL.COM";
    when ('Y') newmail=scan(email,1,'@')||"@YAHOO.COM";
    when ('H') newmail=scan(email,1,'@')||"@HOTMAIL.COM";
    otherwise newmail="";
  end;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 889 views
  • 6 likes
  • 3 in conversation