BookmarkSubscribeRSS Feed
kristindlcrz
Calcite | Level 5

Hi,

 

So I need to extract the strings after a certain number of numerics. Although the problem is that the number of numerics is inconsistent. How do I get the string after the numbers?

 

For example, my data is the following:

1234567aaa@mail.com 

12345bbb@mail.com

123456789ccc@mail.com 

 

And I want my output to be:

aaa@mail.com 

bbb@mail.com 

ccc@mail.com 

 

Is this possible in SAS?

 

Thank you!

 

6 REPLIES 6
kristindlcrz
Calcite | Level 5

Also, the string could be like these:

 

12345ddd23@mail.com  

 

I want to be able to collect all of the characters after the numeric so the desired output would be:

 

ddd23@mail.com 

 

 

Thank you!

 

 

hhinohar
Quartz | Level 8

This is a quick sample.

data have;
	input email:$30.;
datalines;
1234567aaa@mail.com 
12345bbb@mail.com
123456789ccc@mail.com 
12345ddd23@mail.com  
;
run;

data want;
	set have;
	email_out=prxchange("s/(\d+)(\w+@\w+.\w+)/$2/i",-1,email);
run;
kristindlcrz
Calcite | Level 5
Will this also cover the emails that have numbers in them?

Such as if the data is 123aaa01@mail.com, the output will still be aaa01@mail.com?
hhinohar
Quartz | Level 8

Yes it does on my SAS Studio.

You're welcome to try.

 

andreas_lds
Jade | Level 19

Another solution without using a regular expression:

data want;
  set have;
  email_sub = substr(email, notdigit(email));
run;

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
  • 6 replies
  • 698 views
  • 1 like
  • 3 in conversation