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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: