BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alexxxxxxx
Pyrite | Level 9

Dear all,

I am processing the variable which inlcudes 'LTD', 'CO', 'CO LTD', 'PLC', 'CORP' and trying to separate the company name from address/introduction information. However, the following variable includes at least two 'company suffix' (i.e., LTD, CO, CO LTD, PLC, CORP), so I expect to process the variable only once. But I do not know how to do it. Could you please give me some suggestions about this?

 

for following data,

data HAVE;
  input NAME_S221 :& $500.;

if find(NAME_S221,' LTD ')>0 and find(NAME_S221,' LTD PARTNERSHIP ')=0 and prxmatch('/(.*) LTD\s?([(\(.*\))|(\[.*\])|(\{.*\})|(''.*'')|(".*")]+)(.*)/',NAME_S221 )=0 then do;
			NAME_B=substr(NAME_S221,1,find(NAME_S221,' LTD ')+3);
			NAME_address=strip(substr(NAME_S221,find(NAME_S221,' LTD ')+5, length(NAME_S221)));
		end;
		if find(NAME_S221,' CO ')>0 and prxmatch('/(.*) CO\s?([(\(.*\))|(\[.*\])|(\{.*\})|(''.*'')|(".*")]+)(.*)/',NAME_S221 )=0 then do;
			NAME_B=substr(NAME_S221,1,find(NAME_S221,' CO ')+2);
			NAME_address=strip(substr(NAME_S221,find(NAME_S221,' CO ')+4, length(NAME_S221)));
		end;
		if find(NAME_S221,' CO LTD ')>0 and prxmatch('/(.*) CO LTD\s?([(\(.*\))|(\[.*\])|(\{.*\})|(''.*'')|(".*")]+)(.*)/',NAME_S221 )=0 then do;
			NAME_B=substr(NAME_S221,1,find(NAME_S221,' CO LTD ')+6);
			NAME_address=strip(substr(NAME_S221,find(NAME_S221,' CO LTD ')+8, length(NAME_S221)));
		end;
		if find(NAME_S221,' PLC ')>0 and prxmatch('/(.*) PLC\s?([(\(.*\))|(\[.*\])|(\{.*\})|(''.*'')|(".*")]+)(.*)/',NAME_S221 )=0 then do;
			NAME_B=substr(NAME_S221,1,find(NAME_S221,' PLC ')+3);
			NAME_address=strip(substr(NAME_S221,find(NAME_S221,' PLC ')+5, length(NAME_S221)));
		end;
		if find(NAME_S221,' CORP ')>0 and prxmatch('/(.*) CORP\s?([(\(.*\))|(\[.*\])|(\{.*\})|(''.*'')|(".*")]+)/',NAME_S221 )=0 then do;
			NAME_B=substr(NAME_S221,1,find(NAME_S221,' CORP ')+4);
			NAME_address=strip(substr(NAME_S221,find(NAME_S221,' CORP ')+6, length(NAME_S221)));
		end;
cards;

BOTO (LICENSES) LTD AN ISLE OF MAN CO OF 3/F
BOTO (LICENSES) LTD AN ISLE OF MAN LTD OF 3/F
BPB LTD A U.K. CORP
BROADCOM UK LTD A DELAWARE CORP
ARCH TIMBER PROTECTION LTD A PRIVATE LIMITED CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM
AVDEL SYSTEMS LTD A BRITISH CO
run;

I get 

NAME_S221NAME_BNAME_address
BOTO (LICENSES) LTD AN ISLE OF MAN CO OF 3/FBOTO (LICENSES) LTD AN ISLE OF MAN COOF 3/F
BOTO (LICENSES) LTD AN ISLE OF MAN LTD OF 3/FBOTO (LICENSES) LTDAN ISLE OF MAN LTD OF 3/F
BPB LTD A U.K. CORPBPB LTD A U.K. CORP 
BROADCOM UK LTD A DELAWARE CORPBROADCOM UK LTD A DELAWARE CORP 
ARCH TIMBER PROTECTION LTD A PRIVATE LIMITED CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOMARCH TIMBER PROTECTION LTD A PRIVATE LIMITED COORGANISED UNDER THE LAWS OF THE UNITED KINDGOM
AVDEL SYSTEMS LTD A BRITISH COAVDEL SYSTEMS LTD A BRITISH CO 

However, I expect to process the variable 'NAME_S221' only once. namely, I expect to get 

NAME_S221NAME_BNAME_address
BOTO (LICENSES) LTDBOTO (LICENSES) LTDAN ISLE OF MAN CO OF 3/F
BOTO (LICENSES) LTD AN ISLE OF MAN LTD OF 3/FBOTO (LICENSES) LTDAN ISLE OF MAN LTD OF 3/F
BPB LTD A U.K. CORPBPB LTDA U.K. CORP
BROADCOM UK LTD A DELAWARE CORPBROADCOM UK LTDA DELAWARE CORP
ARCH TIMBER PROTECTION LTD A PRIVATE LIMITED CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOMARCH TIMBER PROTECTION LTDA PRIVATE LIMITED CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM
AVDEL SYSTEMS LTD A BRITISH COAVDEL SYSTEMS LTDA BRITISH CO
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

When you are searching for values that may appear as part of another key value, such as your 'CO' and 'LTD' that are part of 'CO LTD' then you likely should have the LONGER value processed first.

 

You may need to have some ELSE. before the second and subsequent "if find(NAME_S221,' LTD ')>0 " clauses.

As written every single one of those comparisons is done and seems to be causing part of your concern.

View solution in original post

1 REPLY 1
ballardw
Super User

When you are searching for values that may appear as part of another key value, such as your 'CO' and 'LTD' that are part of 'CO LTD' then you likely should have the LONGER value processed first.

 

You may need to have some ELSE. before the second and subsequent "if find(NAME_S221,' LTD ')>0 " clauses.

As written every single one of those comparisons is done and seems to be causing part of your concern.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 286 views
  • 0 likes
  • 2 in conversation