BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8

Hi Experts

How to extract last 10 digits without substr ,scan ,reverse ,regex functions

data  dsn;
input phone $ 50.;
cards;
S001 110064 9873628374
S002 110065 8447752736
S003 110023 9811537264
;
run;
3 REPLIES 3
PaigeMiller
Diamond | Level 26

I don't accept your restrictions, and so it is easy to do. No reason to make it harder.

 

In this case, use the SCAN function.

 

last_10=scan(phone,3,' ');

 

--
Paige Miller
Astounding
PROC Star

This is not difficult for SAS:

data  dsn;
length phone $ 50; 
input phone phone phone;
cards;
S001 110064 9873628374
S002 110065 8447752736
S003 110023 9811537264
;

But why would you want to prohibit the most useful tools.  To illustrate, here's a task for you.  Try to eat a bowl of cereal and milk without using a spoon.

Ksharp
Super User

It looks like  an interview question ?

data  dsn;
input phone $ 50.;
length dummy $ 12;
dummy=phone;
want=strip(tranwrd(phone,dummy,' '));
drop dummy;
cards;
S001 110064 9873628374
S002 110065 8447752736
S003 110023 9811537264
;
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
  • 3 replies
  • 164 views
  • 1 like
  • 4 in conversation