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

Hi experts,

 

the data set I have bunch of post-fixes in the end of the company, example (post-fixes):

(canada)
(india)
ab
ag
bv
co
co ltd
gmbh
inc
india
limited
llc
ltd
mbh
nv
plc
private limited
pte ltd
pty ltd
pvt ltd
s.a
sa
sl
spa
srl
usa
corp
sro
a/s

 

 

what I want to achieve is, remove those from the comapnies names.

the postfixes and actual comapnies names, their are a single blank within. example:

  180 Medical Inc

  1ST Bio Therapeutics Inc

  1ST Bio Therapeutics INC

  1abtik ag

  Camurus AB

  Korning AG

  PlasmaChem GmbH

  PlasmaChem GMBH

 

how do I remove those post-fixes from original data set?

and some post fixes are written upper-case, and some are in lower-case, some are mixed.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @jimmychoi 

 

Here is an attempt to do this. Does that meet your expectations?

data word_list;
	input word $20.;
	if findc(word,"/") then word=tranwrd(word,"/",".");
	datalines;
(canada)
(india)
ab
ag
bv
co
co ltd
gmbh
inc
india
limited
llc
ltd
mbh
nv
plc
private limited
pte ltd
pty ltd
pvt ltd
s.a
sa
sl
spa
srl
usa
corp
sro
a/s
;
run;

data have;
	input company $80.;
	datalines;
180 Medical Inc
1ST Bio Therapeutics Inc
1ST Bio Therapeutics INC
1abtik ag
Camurus AB
Korning AG
PlasmaChem GmbH
PlasmaChem GMBH
;
run;

proc sql noprint;
	select quote(trim(word),"'")
	into:word_list separated by ","
	from word_list
	order by countw(word) desc;
quit;

data want;
	set have;
	company = tranwrd(company,"/",".");
	array _list(&sqlobs) $ _temporary_ (&word_list);
	do i=1 to dim(_list);
		if find(company,_list(i),"i")>0 then do;
			company = prxchange(cats("s/(\(?\b",_list(i),"\b\)?\s*)$//i"),-1,company);
		end;
	end;
	drop i;
run;


Capture d’écran 2020-02-04 à 17.51.00.png

 

View solution in original post

1 REPLY 1
ed_sas_member
Meteorite | Level 14

Hi @jimmychoi 

 

Here is an attempt to do this. Does that meet your expectations?

data word_list;
	input word $20.;
	if findc(word,"/") then word=tranwrd(word,"/",".");
	datalines;
(canada)
(india)
ab
ag
bv
co
co ltd
gmbh
inc
india
limited
llc
ltd
mbh
nv
plc
private limited
pte ltd
pty ltd
pvt ltd
s.a
sa
sl
spa
srl
usa
corp
sro
a/s
;
run;

data have;
	input company $80.;
	datalines;
180 Medical Inc
1ST Bio Therapeutics Inc
1ST Bio Therapeutics INC
1abtik ag
Camurus AB
Korning AG
PlasmaChem GmbH
PlasmaChem GMBH
;
run;

proc sql noprint;
	select quote(trim(word),"'")
	into:word_list separated by ","
	from word_list
	order by countw(word) desc;
quit;

data want;
	set have;
	company = tranwrd(company,"/",".");
	array _list(&sqlobs) $ _temporary_ (&word_list);
	do i=1 to dim(_list);
		if find(company,_list(i),"i")>0 then do;
			company = prxchange(cats("s/(\(?\b",_list(i),"\b\)?\s*)$//i"),-1,company);
		end;
	end;
	drop i;
run;


Capture d’écran 2020-02-04 à 17.51.00.png

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 493 views
  • 1 like
  • 2 in conversation