I have a column with this type of structure:
Last_Name, First_Name Middle_Name 123456789 Company NameX
May I know what function should I use to get the value Company NameX? Thanks
please try below code
data have;
input text&$100.;
cards;
Last_Name, First_Name Middle_Name 123456789 Company NameX
;
data want;
set have;
want=prxchange('s/(.*\d+\s)(\w+)/$2/oi',-1,strip(text));
run;
alternatively with substr
data want;
set have;
want=substr(text,index(text,scan(text,5,'')));
run;
namex=scan(text,-1);
company=scan(text,-2);
To get any value after the last digit:
data WANT;
STR1='Last_Name, First_Name Middle_Name 123456789 Company NameX';
STR2=prxchange('s/.*\d //',1,strip(STR1));
run;
The scan() function - SCAN(string, count <, character-list <, modifier>>) - with a negative number for the count parameter allows to search a string from the right to the left. A -1 will return the last term (=the first term from the right).
Follow-up at https://communities.sas.com/t5/SAS-Programming/How-to-read-delimiter-if-it-s-a-multiple-spaces/m-p/6...
Not sure if i should merge the two messages.
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.