BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data split;
input email$;
cards;
sureshkumar@gmail.com
satish_154@gmail.com
nareshkumar_25@hotmail.com
;
run;

How to extract name from mailaddress 

4 REPLIES 4
hhinohar
Quartz | Level 8
data want;
	set split;
	name=scan(email,1,"@");
run;
BrahmanandaRao
Lapis Lazuli | Level 10

suppose name contains zero then how to extract including zeros also

sureshkumar@gmail.com
satish_0154@gmail.com
nareshkumar_250@hotmail.com

hhinohar
Quartz | Level 8

Tested including split data set.

data split;
length email $30;
input email $ ;
cards;
sureshkumar@gmail.com
satish_0154@gmail.com
nareshkumar_250@hotmail.com
sureshkumar@gmail.com
satish_154@gmail.com
nareshkumar_25@hotmail.com
;
run;

*1;
data want;
	set split;
	name=scan(email,1,"@");
run;

*2;
data want;
	set split;
	name=prxchange("s/(.+)(@)(.+)/$1/",-1,email);
run;

hhinohar_0-1607120895075.png

 

hhinohar
Quartz | Level 8

I came to notice split data set provided has an issue.

 

original split dataset:

data split;
input email$;
cards;
sureshkumar@gmail.com
satish_154@gmail.com
nareshkumar_25@hotmail.com
;
run;

hhinohar_1-1607122125669.png

 

Split dataset only uses list input statement and has no length specified,which leads to email variable values truncated to 8 bytes.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lestmtsref&docsetTarget=n...


-----------------------------------------------------------------------------------------------------------------------------------------------------------
Character input values cannot be longer than 8 bytes unless the variable is given a longer length in an earlier LENGTH, ATTRIB, or INFORMAT statement.
-----------------------------------------------------------------------------------------------------------------------------------------------------------

 

If above data step is executed, result will show only 8 bytes.

 

-----------------
sureshku
satish_1
nareshku
-----------------

 

With recent update it will show this.

-----------------
1 sureshku
2 satish_0
3 nareshku
-----------------

 

With provided dataset , any output will not meet your expectation as there is no "@" character in split dataset in the first place.
As stated in the above link, adding length statement in split data set will give longer length result and correct expected result with my program.

 

-----------------
length email $30;
-----------------

 

corrected split dataset:

data split;
length email $30;
input email $ ;
cards;
sureshkumar@gmail.com
satish_0154@gmail.com
nareshkumar_250@hotmail.com
sureshkumar@gmail.com
satish_154@gmail.com
nareshkumar_25@hotmail.com
;
run;

hhinohar_2-1607122363234.png

 

*1;
data want;
	set split;
	name=scan(email,1,"@");
run;

*2;
data want;
	set split;
	name=prxchange("s/(.+)(@)(.+)/$1/",-1,email);
run;

hhinohar_3-1607122437913.png

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1130 views
  • 0 likes
  • 2 in conversation