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;
Show us the code you have already tried.
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.
I want age in numeric, yes only for this scenario age is only two digit long.
length() is not needed and actually dangerous (think of kids and centenarians).
Use anydigit() to find the first occurence of a digit, and substr() from there.
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.
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.