BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vishalrajpoot3
Obsidian | Level 7

Will someone provide me the solution for subjected problem with the below data, I want to extract age from the below data using 'Length' and 'Substr' function.

 

 

Data test;
input nameage $10.;
datalines;
Ram24
Albertaa26
Bob85
AB23
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
akash1088
Obsidian | Level 7
Hi Vishal,

Age=input(substr(nameage,length(nameage)-1),8.);

In this way you can use substr and length function both.If you are sure about that age is coming as a last 2 digit.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Show us the code you have already tried.

--
Paige Miller
Astounding
PROC Star

Do you want the extracted age to be character or numeric?

 

Are you being forced to use the tools you mentioned?  They're not the best ones for the job.  Using those only might force you to assume that the age is always two digits long.

vishalrajpoot3
Obsidian | Level 7

 

I want age in numeric, yes only for this scenario age is only two digit long.  

akash1088
Obsidian | Level 7
Hi Vishal,

Age=input(substr(nameage,length(nameage)-1),8.);

In this way you can use substr and length function both.If you are sure about that age is coming as a last 2 digit.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 687 views
  • 0 likes
  • 5 in conversation