Dear All,
I have dataset with the one variable X. I would like to write a query to exclude the first numerical, special character part and start reading from the first occurrence of the alphabet.
10 - SEASONAL ALLERGIES - UN/UNK/1954
3333 ** COMMON COLD - 10/JAN/2015
222 ### RECURRENT SINUSITIS - UN/UNK/2003
44444 @@ INSOMNIA - UN/UNK/2008
The output should look like this.
SEASONAL ALLERGIES - UN/UNK/1954
COMMON COLD - 10/JAN/2015
RECURRENT SINUSITIS - UN/UNK/2003
INSOMNIA - UN/UNK/2008
Thanks in advance
Rakesh
You could use the VERIFY() function.
data have;
input x $60.;
cards4;
10 - SEASONAL ALLERGIES - UN/UNK/1954
3333 ** COMMON COLD - 10/JAN/2015
222 ### RECURRENT SINUSITIS - UN/UNK/2003
44444 @@ INSOMNIA - UN/UNK/2008
;;;;
data want ;
set have ;
x=substr(x,max(1,verify(x,'012345678 -+*#@')));
run;
You could use the VERIFY() function.
data have;
input x $60.;
cards4;
10 - SEASONAL ALLERGIES - UN/UNK/1954
3333 ** COMMON COLD - 10/JAN/2015
222 ### RECURRENT SINUSITIS - UN/UNK/2003
44444 @@ INSOMNIA - UN/UNK/2008
;;;;
data want ;
set have ;
x=substr(x,max(1,verify(x,'012345678 -+*#@')));
run;
You could also substr from the first occurence of an alphabetic character:
new_var=substr(findc(old_var,"","a"));
This will substring from first alpha character to the end.
I don't like Tom's code . data have; input x $60.; cards4; 10 - SEASONAL ALLERGIES - UN/UNK/1954 3333 ** COMMON COLD - 10/JAN/2015 222 ### RECURRENT SINUSITIS - UN/UNK/2003 44444 @@ INSOMNIA - UN/UNK/2008 ;;;; data want ; set have ; x=substr(x,max(1,verify(x,'012345678 -+*#@'))); me=substr(x,prxmatch('/[a-z]/i',x)); run;
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.