data split;
input email$;
cards;
sureshkumar@gmail.com
satish_154@gmail.com
nareshkumar_25@hotmail.com
;
run;
How to extract name from mailaddress
data want;
set split;
name=scan(email,1,"@");
run;
suppose name contains zero then how to extract including zeros also
sureshkumar@gmail.com
satish_0154@gmail.com
nareshkumar_250@hotmail.com
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;
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;
Split dataset only uses list input statement and has no length specified,which leads to email variable values truncated to 8 bytes.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
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;
*1;
data want;
set split;
name=scan(email,1,"@");
run;
*2;
data want;
set split;
name=prxchange("s/(.+)(@)(.+)/$1/",-1,email);
run;
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!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.