BookmarkSubscribeRSS Feed
SASbeginner20
Calcite | Level 5

What procedure would I use to remove multiple phrases within a string?

I want to remove the "LLC", "Inc", and "Incorporated"

Is there a way to remove this all in one line/step of code rather than multiple steps?

Name

Company 1 LLC

Company 2 Incorporated

Company 3 Inc.

Thanks so much.

3 REPLIES 3
dcruik
Lapis Lazuli | Level 10

You could use the tranwrd() function multiple times on the Name field to replace a substring with a different substring, in this instance a blank.  I would assume you don't want the space after 1 in Company 1 LLC, so I would try the following:

data want;

set have;

Name=tranwrd(Name," LLC","");

Name=tranwrd(Name," Incorporated","");

Name=tranwrd(Name," Inc.","");

run;

Hope this helps!

Patrick
Opal | Level 21

A RegEx option which will only remove the targeted strings if they are at the very end.

data have;

  infile datalines truncover;

  input company_name $40.;

  datalines;

Company 1 LLC

Company 2 Incorporated

Company LLC 3 Inc.

Lend Lease Group LLC Inc.

;

run;

data want;

  set have;

  length company_name_root $40;

  company_name_root=prxchange('s/(LLC|Incorporated|Inc\.)\s*$//oi',1,company_name);

run;

stat_sas
Ammonite | Level 13

data want(drop=list);

set have;

length list $30;

do list = 'LLC', 'Incorporated', 'Inc.';

  Name = tranwrd(strip(Name),strip(list),'');

end;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 16755 views
  • 0 likes
  • 4 in conversation