HI,
My input field is something like this -
ALICE REV 2-KY/CB
ALICE-REV 2/BHP
Audition/BTT
Audition-CK/BT
and my output field needs to be somehting like this -
ALICE
Audition
I have a vague idea about PRX functions. Any help will be appreciated.
Thanks,
saspert
Have a go with this sample, check the doc for the Tables of Perl Regular Expression (PRX) Metacharacters
data want;
infile cards ;
input text $64.;
wordEnd = prxmatch("/\W+\b/", text);
word = substr(text, 1, wordEnd-1);
putlog _all_;
cards;
ALICE REV 2-KY/CB
ALICE-REV 2/BHP
Audition/BTT
Audition-CK/BT
;
Bruno
If you know the delimiters that might appear in your data, you can code this simply:
data want;
set have;
string = scan(string, 1, '- /');
run;
Be sure to include a blank as one of the delimiters.
proc sql;
select distinct(prxchange('s/(^\w+)\W+?.*/$1/i',1,text)) as string from want;
quit;
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.