How to extract multiple email addresses stored in a String variable in SAS

sas
data_wrangling
string

#1

Hi,

I have email addresses stored in a variable EMAIL of SAS data set. It is a free text field so user has given more than one Email address with various delimiter like space, comma, semicolon, colon and other. Below is the sample of values stored:-

EMAIL
David@Gmail.com, David@Yahoo.com
Steve@Gmail.com Steve12@sify.com
Rakesh@sify.com

Can you help me to extract Email address and store it delimited by semicolon only to other variable?

Thx, Steve


#2

@Steve
It can be done using Substr and Find functions.

Find():- Searches for a specific substring of characters within a character string.

Syntax:-  FIND(string, substring <,startpos>)

SUBSTR():- Extract a given number of characters of string from specified position

Syntax:- SUBSTR(String,From_Position,Number_Character)

Let’s look at the solution of problem:

/*Email Data Set */
Data Email;
Input Email $35.;
datalines;
David@Gmail.com, David@Yahoo.com
Steve@Gmail.com Steve12@sify.com
Rakesh@sify.com
;
Run;



/*Email Extraction */
	Data Email_Extract;
	Set Email;
	Email_1=Substr(EMAIL,1,find(Email,'.com')+3);
	Email_2=Substr(EMAIL,find(Email,'.com')+5,find(Email,'.com')+4);
	Run;

Regards,
Sunil