DATA emails;
INPUT email $50.;
DATALINES;
john.doe@example.com
jane.smith@company.org
robert.johnson@email.net
sarah.lee-wong@domain.co.uk
mary.jane.parker@email.com
tom.m.hanks@movies.com
a.einstein@physics.edu
;
RUN;
data want;
set emails;
temp=scan(email,1,'@');
if countw(temp,,'ka')=3 then do;
first=scan(temp,1,,'ka');
middle=scan(temp,2,,'ka');
last=scan(temp,3,,'ka');
end;
else do;
first=scan(temp,1,,'ka');
last=scan(temp,-1,,'ka');
end;
drop temp;
run;