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:

[email protected] 

[email protected]

[email protected] 

 

And I want my output to be:

[email protected] 

[email protected] 

[email protected] 

 

Is this possible in SAS?

 

Thank you!

 

6 REPLIES 6
kristindlcrz
Calcite | Level 5

Also, the string could be like these:

 

[email protected]  

 

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

 

[email protected] 

 

 

Thank you!

 

 

hhinohar
Quartz | Level 8

This is a quick sample.

data have;
	input email:$30.;
datalines;
[email protected] 
[email protected]
[email protected] 
[email protected]  
;
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 [email protected], the output will still be [email protected]?
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;

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2389 views
  • 1 like
  • 3 in conversation